xP: fix non-ASCII text completion
This commit is contained in:
parent
62773acaa0
commit
23deca45c9
@ -129,6 +129,9 @@ class RelayRpc extends EventTarget {
|
|||||||
|
|
||||||
// ---- Utilities --------------------------------------------------------------
|
// ---- Utilities --------------------------------------------------------------
|
||||||
|
|
||||||
|
function utf8Encode(s) { return new TextEncoder().encode(s) }
|
||||||
|
function utf8Decode(s) { return new TextDecoder().decode(s) }
|
||||||
|
|
||||||
// On macOS, the Alt/Option key transforms characters, which basically breaks
|
// On macOS, the Alt/Option key transforms characters, which basically breaks
|
||||||
// all event.altKey shortcuts, so require combining them with Control as well
|
// all event.altKey shortcuts, so require combining them with Control as well
|
||||||
// on that system.
|
// on that system.
|
||||||
@ -598,15 +601,22 @@ let Input = {
|
|||||||
command: 'BufferComplete',
|
command: 'BufferComplete',
|
||||||
bufferName: bufferCurrent,
|
bufferName: bufferCurrent,
|
||||||
text: textarea.value,
|
text: textarea.value,
|
||||||
position: textarea.selectionEnd,
|
position: utf8Encode(
|
||||||
|
textarea.value.slice(0, textarea.selectionEnd)).length,
|
||||||
}).then(resp => {
|
}).then(resp => {
|
||||||
if (!Input.stamp(textarea).every((v, k) => v === state[k]))
|
if (!Input.stamp(textarea).every((v, k) => v === state[k]))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
let preceding = utf8Encode(textarea.value).slice(0, resp.start)
|
||||||
|
let start = utf8Decode(preceding).length
|
||||||
|
|
||||||
// TODO: Somehow display remaining options, or cycle through.
|
// TODO: Somehow display remaining options, or cycle through.
|
||||||
if (resp.completions.length)
|
if (resp.completions.length) {
|
||||||
textarea.setRangeText(resp.completions[0],
|
textarea.setRangeText(resp.completions[0],
|
||||||
resp.start, textarea.selectionEnd, 'end')
|
start, textarea.selectionEnd, 'end')
|
||||||
|
} else {
|
||||||
|
beep()
|
||||||
|
}
|
||||||
if (resp.completions.length === 1)
|
if (resp.completions.length === 1)
|
||||||
textarea.setRangeText(' ',
|
textarea.setRangeText(' ',
|
||||||
textarea.selectionStart, textarea.selectionEnd, 'end')
|
textarea.selectionStart, textarea.selectionEnd, 'end')
|
||||||
|
Loading…
Reference in New Issue
Block a user