mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-19 20:51:42 +00:00
added note template feature
This commit is contained in:
@@ -197,13 +197,33 @@ export default class CodeEditor extends React.Component {
|
|||||||
|
|
||||||
expandSnippet (line, cursor, cm, snippets) {
|
expandSnippet (line, cursor, cm, snippets) {
|
||||||
const wordBeforeCursor = this.getWordBeforeCursor(line, cursor.line, cursor.ch)
|
const wordBeforeCursor = this.getWordBeforeCursor(line, cursor.line, cursor.ch)
|
||||||
|
const templateCursorString = ':{}'
|
||||||
for (let i = 0; i < snippets.length; i++) {
|
for (let i = 0; i < snippets.length; i++) {
|
||||||
if (snippets[i].prefix.indexOf(wordBeforeCursor.text) !== -1) {
|
if (snippets[i].prefix.indexOf(wordBeforeCursor.text) !== -1) {
|
||||||
cm.replaceRange(
|
if (snippets[i].content.indexOf(templateCursorString) !== -1) {
|
||||||
snippets[i].content,
|
let snippetLines = snippets[i].content.split('\n')
|
||||||
wordBeforeCursor.range.from,
|
let cursorLineNumber = 0
|
||||||
wordBeforeCursor.range.to
|
let cursorLinePosition = 0
|
||||||
)
|
for (let j = 0; j < snippetLines.length; j++) {
|
||||||
|
let 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 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cm.replaceRange(
|
||||||
|
snippets[i].content,
|
||||||
|
wordBeforeCursor.range.from,
|
||||||
|
wordBeforeCursor.range.to
|
||||||
|
)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user