aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/editor.mjs15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/editor.mjs b/src/editor.mjs
index 5a51fbe..c3c51ef 100644
--- a/src/editor.mjs
+++ b/src/editor.mjs
@@ -1031,7 +1031,8 @@ document.addEventListener('selectionchange', () => {
1031 const content = selection.getRangeAt(0).toString() 1031 const content = selection.getRangeAt(0).toString()
1032 const parentWithSourceLine = selection.anchorNode.parentElement.closest('.source-line') 1032 const parentWithSourceLine = selection.anchorNode.parentElement.closest('.source-line')
1033 const lineStart = Number(parentWithSourceLine?.dataset?.sourceLine ?? NaN) 1033 const lineStart = Number(parentWithSourceLine?.dataset?.sourceLine ?? NaN)
1034 const lineEnd = Number(parentWithSourceLine?.nextSibling?.dataset?.sourceLine ?? NaN) 1034 const nextSourceLine = parentWithSourceLine?.nextSibling?.dataset?.sourceLine
1035 const lineEnd = Number(nextSourceLine) ?? cm.doc.size
1035 // TODO Also return when range contains anchor element 1036 // TODO Also return when range contains anchor element
1036 if (content.includes('\n') || isNaN(lineStart)) { 1037 if (content.includes('\n') || isNaN(lineStart)) {
1037 cm.setSelection(cm.getCursor()) 1038 cm.setSelection(cm.getCursor())
@@ -1056,16 +1057,16 @@ document.addEventListener('selectionchange', () => {
1056 while (index === -1) { 1057 while (index === -1) {
1057 anchor.line += 1 1058 anchor.line += 1
1058 anchor.ch = 0 1059 anchor.ch = 0
1059 if (anchor.line >= lineEnd) { 1060 if (anchor.line >= lineEnd) return
1060 cm.setSelection(cm.setCursor()) 1061
1061 return 1062 index = cm.getLine(anchor.line).indexOf(text)
1062 }
1063 index = cm.getLine(anchor.line)?.indexOf(text)
1064 } 1063 }
1065 anchor.ch = index + text.length 1064 anchor.ch = index + text.length
1066 }) 1065 })
1067 1066
1068 cm.setSelection({ line: anchor.line, ch: anchor.ch - content.length }, anchor) 1067 const focus = { line: anchor.line, ch: anchor.ch - content.length }
1068 cm.setSelection(focus, anchor)
1069 cm.scrollIntoView(focus)
1069 } 1070 }
1070}) 1071})
1071 1072