Skip to content

Commit

Permalink
fix: wrong selection index after button input
Browse files Browse the repository at this point in the history
I don't really understand why focusing beforehand gets it working. 🤷
#30
  • Loading branch information
Attacktive committed Dec 6, 2023
1 parent 3c16c21 commit e8f3c43
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ function drawInputButtons() {
const start = input.selectionStart ?? input.value.length;
const end = input.selectionEnd ?? input.value.length;

input.setRangeText(target.innerText, start, end);

const newSelectionStart = end + target.innerText.length + 1;
input.selectionStart = newSelectionStart;
input.selectionEnd = newSelectionStart;
input.focus();
input.setRangeText(target.innerText, start, end, "end");
};

const consonantInputButtonArea = document.querySelector("#input-button-area-consonants") as HTMLDivElement;
Expand Down

0 comments on commit e8f3c43

Please sign in to comment.