Skip to content

Commit 637225c

Browse files
committed
fix cursor position after expending snippet
1 parent fdb1ef5 commit 637225c

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

browser/components/CodeEditor.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -317,22 +317,28 @@ export default class CodeEditor extends React.Component {
317317
const snippetLines = snippets[i].content.split('\n')
318318
let cursorLineNumber = 0
319319
let cursorLinePosition = 0
320+
321+
let cursorIndex
320322
for (let j = 0; j < snippetLines.length; j++) {
321-
const cursorIndex = snippetLines[j].indexOf(templateCursorString)
323+
cursorIndex = snippetLines[j].indexOf(templateCursorString)
324+
322325
if (cursorIndex !== -1) {
323326
cursorLineNumber = j
324327
cursorLinePosition = cursorIndex
325-
cm.replaceRange(
326-
snippets[i].content.replace(templateCursorString, ''),
327-
wordBeforeCursor.range.from,
328-
wordBeforeCursor.range.to
329-
)
330-
cm.setCursor({
331-
line: cursor.line + cursorLineNumber,
332-
ch: cursorLinePosition
333-
})
328+
329+
break
334330
}
335331
}
332+
333+
cm.replaceRange(
334+
snippets[i].content.replace(templateCursorString, ''),
335+
wordBeforeCursor.range.from,
336+
wordBeforeCursor.range.to
337+
)
338+
cm.setCursor({
339+
line: cursor.line + cursorLineNumber,
340+
ch: cursorLinePosition + cursor.ch - wordBeforeCursor.text.length
341+
})
336342
} else {
337343
cm.replaceRange(
338344
snippets[i].content,

0 commit comments

Comments
 (0)