upd: update completion

This commit is contained in:
purocean
2022-01-04 14:27:55 +08:00
parent 40489312be
commit ba3b5a2bdb
+8 -7
View File
@@ -141,7 +141,7 @@ function processCursorChange (source: string, position: Monaco.Position) {
const prevContent = getLineContent(line - 1)
// auto increase order list item number
const reg = /^\s*(\d+)\./
const reg = /^\s*(\d+)[.)]/
const match = prevContent.match(reg)
if (match && reg.test(content)) {
const num = isTab ? 0 : parseInt(match[0] || '0')
@@ -157,7 +157,7 @@ function processCursorChange (source: string, position: Monaco.Position) {
}
if (num !== newNum) {
replaceLine(line, content.replace(/\d+\./, `${newNum}.`))
replaceLine(line, content.replace(/\d+/, `${newNum}`))
}
}
}
@@ -172,11 +172,11 @@ function processCursorChange (source: string, position: Monaco.Position) {
if (
eolNumber === position.column &&
/^\s*(?:[*+->]|\d+\.)/.test(content)
/^\s*(?:[*+->]|\d+[.)])/.test(content)
) {
const indent = getOneIndent()
const val = content.trimEnd()
const end = /[-+*\].>]$/.test(val) ? ' ' : ''
const end = /[-+*\].>)]$/.test(val) ? ' ' : ''
replaceLine(position.lineNumber, indent + val + end)
}
} else if (isEnter) {
@@ -188,9 +188,9 @@ function processCursorChange (source: string, position: Monaco.Position) {
const content = getLineContent(line)
const prevContent = getLineContent(line - 1)
const nextContent = getLineContent(line + 1)
const emptyItemReg = /^\s*(?:[*+->]|\d+\.|[*+-] \[ \])\s*$/
const emptyItemReg = /^\s*(?:[*+->]|\d+[.)]|[*+-] \[ \])\s*$/
if (
/^\s*(?:[*+->]|\d+\.)/.test(prevContent) && // previous content must a item
/^\s*(?:[*+->]|\d+[.)])/.test(prevContent) && // previous content must a item
emptyItemReg.test(content) && // current line content must a empty item
emptyItemReg.test(nextContent) // next line content must a empty item
) {
@@ -297,7 +297,8 @@ export default {
{ beforeText: /^\s*\+ .*$/, action: { indentAction: monaco.languages.IndentAction.None, appendText: '+ ' } },
{ beforeText: /^\s*- .*$/, action: { indentAction: monaco.languages.IndentAction.None, appendText: '- ' } },
{ beforeText: /^\s*\* .*$/, action: { indentAction: monaco.languages.IndentAction.None, appendText: '* ' } },
{ beforeText: /^\s*\d+\. .*$/, action: { indentAction: monaco.languages.IndentAction.None, appendText: '1. ' } }
{ beforeText: /^\s*\d+\. .*$/, action: { indentAction: monaco.languages.IndentAction.None, appendText: '1. ' } },
{ beforeText: /^\s*\d+\) .*$/, action: { indentAction: monaco.languages.IndentAction.None, appendText: '1) ' } },
]
})