MCPcopy
hub / github.com/antonmedv/codejar / handleNewLine

Function handleNewLine

codejar.ts:317–346  ·  view source on GitHub ↗
(event: KeyboardEvent)

Source from the content-addressed store, hash-verified

315 }
316
317 function handleNewLine(event: KeyboardEvent) {
318 if (event.key === 'Enter') {
319 const before = beforeCursor()
320 const after = afterCursor()
321
322 let [padding] = findPadding(before)
323 let newLinePadding = padding
324
325 // If last symbol is "{" ident new line
326 if (options.indentOn.test(before)) {
327 newLinePadding += options.tab
328 }
329
330 // Preserve padding
331 if (newLinePadding.length > 0) {
332 preventDefault(event)
333 event.stopPropagation()
334 insert('\n' + newLinePadding)
335 } else {
336 legacyNewLineFix(event)
337 }
338
339 // Place adjacent "}" on next line
340 if (newLinePadding !== padding && options.moveToNewLine.test(after)) {
341 const pos = save()
342 insert('\n' + padding)
343 restore(pos)
344 }
345 }
346 }
347
348 function legacyNewLineFix(event: KeyboardEvent) {
349 // Firefox does not support plaintext-only mode

Callers 1

CodeJarFunction · 0.85

Calls 8

beforeCursorFunction · 0.85
afterCursorFunction · 0.85
findPaddingFunction · 0.85
preventDefaultFunction · 0.85
insertFunction · 0.85
legacyNewLineFixFunction · 0.85
saveFunction · 0.85
restoreFunction · 0.85

Tested by

no test coverage detected