Quick fix for the caret composition issue

This commit is contained in:
Mona Mayrhofer 2022-10-23 16:36:16 +02:00
parent e50d398195
commit 77bd037f26
No known key found for this signature in database
GPG Key ID: 5C83114FA383C6A0

View File

@ -53,7 +53,7 @@
History, History,
} }
function setText(text: string, isFinalBeforeSubmit = false) { function setText(text: string, isFinalBeforeSubmit = false, isComposing = false) {
const [highlighted, offset] = highlight( const [highlighted, offset] = highlight(
text, text,
isFinalBeforeSubmit isFinalBeforeSubmit
@ -62,8 +62,10 @@
); );
const prevCursorPos = inputElement.selectionStart; const prevCursorPos = inputElement.selectionStart;
setHtml(highlighted); setHtml(highlighted);
if(!isComposing){
setCaret(prevCursorPos + offset); setCaret(prevCursorPos + offset);
} }
}
function setHtml(html: string) { function setHtml(html: string) {
highlightedTextElement.innerHTML = html; highlightedTextElement.innerHTML = html;
@ -226,7 +228,7 @@
const event = e as InputEvent; const event = e as InputEvent;
const target = event.target as HTMLInputElement; const target = event.target as HTMLInputElement;
setText(target.value == "\n" ? "" : target.value); setText(target.value == "\n" ? "" : target.value, undefined, event.isComposing);
if (event.data == "(") { if (event.data == "(") {
insertText(")"); insertText(")");