Skip to content

Commit ad3b7b3

Browse files
committed
fix: backspacing causing desync on some platforms
1 parent 8c035c1 commit ad3b7b3

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

frontend/src/ts/input/input-element.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const el = document.querySelector("#wordsInput") as HTMLInputElement;
1+
const el = document.querySelector("#wordsInput") as HTMLTextAreaElement;
22

33
if (el === null) {
44
throw new Error("Words input element not found");
55
}
66

7-
export function getInputElement(): HTMLInputElement {
7+
export function getInputElement(): HTMLTextAreaElement {
88
return el;
99
}
1010

frontend/src/ts/input/listeners/misc.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,17 @@ inputEl.addEventListener("select selectstart", (event) => {
2020

2121
inputEl.addEventListener("selectionchange", (event) => {
2222
const selection = window.getSelection();
23+
2324
console.debug("wordsInput event selectionchange", {
2425
event,
2526
selection: selection?.toString(),
2627
isCollapsed: selection?.isCollapsed,
27-
selectionStart: (event.target as HTMLInputElement).selectionStart,
28-
selectionEnd: (event.target as HTMLInputElement).selectionEnd,
28+
selectionStart: inputEl.selectionStart,
29+
selectionEnd: inputEl.selectionEnd,
2930
});
30-
const el = event.target;
31-
if (el === null || !(el instanceof HTMLInputElement)) {
32-
return;
33-
}
3431

35-
const hasSelectedText = el.selectionStart !== el.selectionEnd;
36-
const isCursorAtEnd = el.selectionStart === el.value.length;
32+
const hasSelectedText = inputEl.selectionStart !== inputEl.selectionEnd;
33+
const isCursorAtEnd = inputEl.selectionStart === inputEl.value.length;
3734
if (hasSelectedText || !isCursorAtEnd) {
3835
moveInputElementCaretToTheEnd();
3936
}

0 commit comments

Comments
 (0)