Make autocompletion work not just at end of line

This commit is contained in:
miruka
2020-08-21 04:44:55 -04:00
parent 1b919ec7be
commit 43b14f3129
4 changed files with 76 additions and 32 deletions

View File

@@ -497,4 +497,18 @@ QtObject {
return sum
}
function getWordAtPosition(text, position) {
// getWordAtPosition("foo bar", 1) → {word: "foo", start: 0, end: 2}
let seen = -1
for (var word of text.split(/(\s+)/)) {
var start = seen + 1
seen += word.length
if (seen >= position) return {word, start, end: seen}
}
return {word, start, end: seen}
}
}