diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-09-07 15:09:43 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-09-07 15:10:17 +0200 |
commit | 2e3005d88b6ee65689f5cf71905b014a56523160 (patch) | |
tree | 293ae79301fdd03acc845aebf507685568fc4c88 /xP | |
parent | 2b13f891c9205e3bd0da7c562ee95d1b9b664e7d (diff) | |
download | xK-2e3005d88b6ee65689f5cf71905b014a56523160.tar.gz xK-2e3005d88b6ee65689f5cf71905b014a56523160.tar.xz xK-2e3005d88b6ee65689f5cf71905b014a56523160.zip |
xP: abort autocomplete when no longer applicable
Diffstat (limited to 'xP')
-rw-r--r-- | xP/public/xP.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/xP/public/xP.js b/xP/public/xP.js index abef57a..7bcfeb2 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -421,16 +421,28 @@ let BufferContainer = { } let Input = { + counter: 0, + stamp: textarea => { + return [Input.counter, + textarea.selectionStart, textarea.selectionEnd, textarea.value] + }, + complete: textarea => { if (textarea.selectionStart !== textarea.selectionEnd) return false + // Cancel any previous autocomplete, and ensure applicability. + Input.counter++ + let state = Input.stamp(textarea) rpc.send({ command: 'BufferComplete', bufferName: bufferCurrent, text: textarea.value, position: textarea.selectionEnd, }).then(resp => { + if (!Input.stamp(textarea).every((v, k) => v === state[k])) + return + // TODO: Somehow display remaining options, or cycle through. if (resp.completions.length) textarea.setRangeText(resp.completions[0], @@ -456,8 +468,6 @@ let Input = { // TODO: And perhaps on other actions, too. rpc.send({command: 'Active'}) - // TODO: Cancel any current autocomplete. - let textarea = event.currentTarget let handled = false switch (event.keyCode) { |