Add disableCandidateNormalization option. Fixes #1719

This commit is contained in:
Francisco Hodge
2022-09-29 19:06:00 -07:00
parent 18384c4517
commit 8282ccee5f
14 changed files with 839 additions and 767 deletions
+12 -6
View File
@@ -133,6 +133,7 @@ class SimpleKeyboard {
* @property {object} excludeFromLayout Buttons to exclude from layout
* @property {number} layoutCandidatesPageSize Determines size of layout candidate list
* @property {boolean} layoutCandidatesCaseSensitiveMatch Determines whether layout candidate match should be case sensitive.
* @property {boolean} disableCandidateNormalization Disables the automatic normalization for selected layout candidates
*/
this.options = {
layoutName: "default",
@@ -374,12 +375,17 @@ class SimpleKeyboard {
candidateValue,
targetElement,
onSelect: (selectedCandidate: string, e: MouseEvent) => {
const { layoutCandidatesCaseSensitiveMatch } = this.options;
const { layoutCandidatesCaseSensitiveMatch, disableCandidateNormalization } = this.options;
let candidateStr = selectedCandidate;
if(!disableCandidateNormalization) {
/**
* Making sure that our suggestions are not composed characters
*/
candidateStr = selectedCandidate.normalize("NFD");
}
/**
* 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 =
@@ -392,7 +398,7 @@ class SimpleKeyboard {
);
const newInputSubstr = inputSubstr.replace(
regexp,
normalizedCandidate
candidateStr
);
const newInput = currentInput.replace(inputSubstr, newInputSubstr);