mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-11 01:44:50 +08:00
fix: backspacing causing desync on some platforms
This commit is contained in:
parent
8c035c1687
commit
ad3b7b37d1
2 changed files with 7 additions and 10 deletions
|
|
@ -1,10 +1,10 @@
|
|||
const el = document.querySelector("#wordsInput") as HTMLInputElement;
|
||||
const el = document.querySelector("#wordsInput") as HTMLTextAreaElement;
|
||||
|
||||
if (el === null) {
|
||||
throw new Error("Words input element not found");
|
||||
}
|
||||
|
||||
export function getInputElement(): HTMLInputElement {
|
||||
export function getInputElement(): HTMLTextAreaElement {
|
||||
return el;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,20 +20,17 @@ inputEl.addEventListener("select selectstart", (event) => {
|
|||
|
||||
inputEl.addEventListener("selectionchange", (event) => {
|
||||
const selection = window.getSelection();
|
||||
|
||||
console.debug("wordsInput event selectionchange", {
|
||||
event,
|
||||
selection: selection?.toString(),
|
||||
isCollapsed: selection?.isCollapsed,
|
||||
selectionStart: (event.target as HTMLInputElement).selectionStart,
|
||||
selectionEnd: (event.target as HTMLInputElement).selectionEnd,
|
||||
selectionStart: inputEl.selectionStart,
|
||||
selectionEnd: inputEl.selectionEnd,
|
||||
});
|
||||
const el = event.target;
|
||||
if (el === null || !(el instanceof HTMLInputElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasSelectedText = el.selectionStart !== el.selectionEnd;
|
||||
const isCursorAtEnd = el.selectionStart === el.value.length;
|
||||
const hasSelectedText = inputEl.selectionStart !== inputEl.selectionEnd;
|
||||
const isCursorAtEnd = inputEl.selectionStart === inputEl.value.length;
|
||||
if (hasSelectedText || !isCursorAtEnd) {
|
||||
moveInputElementCaretToTheEnd();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue