refactoring
This commit is contained in:
@@ -35,23 +35,23 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch {
|
|||||||
? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm')
|
? new RegExp(`${prefix}${escapedChar}.*?(?=\\s${escapedChar}|$)`, 'gm')
|
||||||
: new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm')
|
: new RegExp(`${prefix}(?:^)?${escapedChar}[^\\s${escapedChar}]*`, 'gm')
|
||||||
|
|
||||||
// Lookup the boundaries of the current node
|
|
||||||
const textFrom = $position.before()
|
const textFrom = $position.before()
|
||||||
|
|
||||||
// Only look up to the cursor, old behavior: textTo = $position.end()
|
|
||||||
const textTo = $position.pos
|
const textTo = $position.pos
|
||||||
|
|
||||||
const text = $position.doc.textBetween(textFrom, textTo, '\0', '\0')
|
const text = $position.doc.textBetween(textFrom, textTo, '\0', '\0')
|
||||||
|
const match = regexp.exec(text)
|
||||||
|
|
||||||
let match = regexp.exec(text)
|
if (!match) {
|
||||||
let position = null
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
while (match !== null) {
|
|
||||||
// JavaScript doesn't have lookbehinds; this hacks a check that first character is " "
|
// JavaScript doesn't have lookbehinds; this hacks a check that first character is " "
|
||||||
// or the line beginning
|
// or the line beginning
|
||||||
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index)
|
const matchPrefix = match.input.slice(Math.max(0, match.index - 1), match.index)
|
||||||
|
|
||||||
if (/^[\s\0]?$/.test(matchPrefix)) {
|
if (!/^[\s\0]?$/.test(matchPrefix)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
// The absolute position of the match in the document
|
// The absolute position of the match in the document
|
||||||
const from = match.index + $position.start()
|
const from = match.index + $position.start()
|
||||||
let to = from + match[0].length
|
let to = from + match[0].length
|
||||||
@@ -65,7 +65,7 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch {
|
|||||||
|
|
||||||
// If the $position is located within the matched substring, return that range
|
// If the $position is located within the matched substring, return that range
|
||||||
if (from < $position.pos && to >= $position.pos) {
|
if (from < $position.pos && to >= $position.pos) {
|
||||||
position = {
|
return {
|
||||||
range: {
|
range: {
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
@@ -74,10 +74,6 @@ export function findSuggestionMatch(config: Trigger): SuggestionMatch {
|
|||||||
text: match[0],
|
text: match[0],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
match = regexp.exec(text)
|
return null
|
||||||
}
|
|
||||||
|
|
||||||
return position
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user