mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Merge pull request #2593 from daiyam/fix-snippet-cursor
fix cursor position after expending snippet
This commit is contained in:
@@ -317,22 +317,28 @@ export default class CodeEditor extends React.Component {
|
|||||||
const snippetLines = snippets[i].content.split('\n')
|
const snippetLines = snippets[i].content.split('\n')
|
||||||
let cursorLineNumber = 0
|
let cursorLineNumber = 0
|
||||||
let cursorLinePosition = 0
|
let cursorLinePosition = 0
|
||||||
|
|
||||||
|
let cursorIndex
|
||||||
for (let j = 0; j < snippetLines.length; j++) {
|
for (let j = 0; j < snippetLines.length; j++) {
|
||||||
const cursorIndex = snippetLines[j].indexOf(templateCursorString)
|
cursorIndex = snippetLines[j].indexOf(templateCursorString)
|
||||||
|
|
||||||
if (cursorIndex !== -1) {
|
if (cursorIndex !== -1) {
|
||||||
cursorLineNumber = j
|
cursorLineNumber = j
|
||||||
cursorLinePosition = cursorIndex
|
cursorLinePosition = cursorIndex
|
||||||
cm.replaceRange(
|
|
||||||
snippets[i].content.replace(templateCursorString, ''),
|
break
|
||||||
wordBeforeCursor.range.from,
|
|
||||||
wordBeforeCursor.range.to
|
|
||||||
)
|
|
||||||
cm.setCursor({
|
|
||||||
line: cursor.line + cursorLineNumber,
|
|
||||||
ch: cursorLinePosition
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
cm.replaceRange(
|
cm.replaceRange(
|
||||||
snippets[i].content,
|
snippets[i].content,
|
||||||
|
|||||||
Reference in New Issue
Block a user