Skip to content

Commit

Permalink
Merge pull request #2593 from daiyam/fix-snippet-cursor
Browse files Browse the repository at this point in the history
fix cursor position after expending snippet
  • Loading branch information
Rokt33r committed Nov 12, 2018
2 parents 4d77053 + 637225c commit 79ee674
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions browser/components/CodeEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,28 @@ export default class CodeEditor extends React.Component {
const snippetLines = snippets[i].content.split('\n')
let cursorLineNumber = 0
let cursorLinePosition = 0

let cursorIndex
for (let j = 0; j < snippetLines.length; j++) {
const cursorIndex = snippetLines[j].indexOf(templateCursorString)
cursorIndex = snippetLines[j].indexOf(templateCursorString)

if (cursorIndex !== -1) {
cursorLineNumber = j
cursorLinePosition = cursorIndex
cm.replaceRange(
snippets[i].content.replace(templateCursorString, ''),
wordBeforeCursor.range.from,
wordBeforeCursor.range.to
)
cm.setCursor({
line: cursor.line + cursorLineNumber,
ch: cursorLinePosition
})

break
}
}

cm.replaceRange(
snippets[i].content.replace(templateCursorString, ''),
wordBeforeCursor.range.from,
wordBeforeCursor.range.to
)
cm.setCursor({
line: cursor.line + cursorLineNumber,
ch: cursorLinePosition + cursor.ch - wordBeforeCursor.text.length
})
} else {
cm.replaceRange(
snippets[i].content,
Expand Down

0 comments on commit 79ee674

Please sign in to comment.