Apply normalization on CandidateBox selection

This commit is contained in:
Francisco Hodge 2022-01-15 16:37:49 -08:00
parent 6cc3f0dd49
commit 413628a046

View File

@ -365,6 +365,10 @@ class SimpleKeyboard {
candidateValue,
targetElement,
onSelect: (selectedCandidate: string, e: MouseEvent) => {
/**
* Making sure that our suggestions are not composed characters
*/
const normalizedCandidate = selectedCandidate.normalize("NFD");
const currentInput = this.getInput(this.options.inputName, true);
const initialCaretPosition = this.getCaretPositionEnd() || 0;
const inputSubstr =
@ -372,7 +376,10 @@ class SimpleKeyboard {
currentInput;
const regexp = new RegExp(`${candidateKey}$`, "gi");
const newInputSubstr = inputSubstr.replace(regexp, selectedCandidate);
const newInputSubstr = inputSubstr.replace(
regexp,
normalizedCandidate
);
const newInput = currentInput.replace(inputSubstr, newInputSubstr);
const caretPositionDiff = newInputSubstr.length - inputSubstr.length;