Add caret position offset when using rtl option. Fixes #1788

This commit is contained in:
Francisco Hodge
2022-11-25 04:01:16 -05:00
parent 56d8fa6c58
commit 11c67de90a
3 changed files with 73 additions and 4 deletions
+50
View File
@@ -1351,4 +1351,54 @@ it('Keyboard will handle selected input with unchanged updatedInput edge case',
expect(keyboard.getInput()).toBe("33");
expect(keyboard.getCaretPosition()).toBe(2);
expect(keyboard.getCaretPositionEnd()).toBe(2);
});
it('Ensure caret position is offset when rtl option is enabled', () => {
const keyboard = new Keyboard({
useMouseEvents: true,
rtl: true,
layout: {
default: ["{bksp} ש ל ו ם"]
}
});
const caretEventHandler = jest.spyOn(keyboard, 'caretEventHandler');
keyboard.getButtonElement("ש").onclick();
keyboard.getButtonElement("ו").onclick();
keyboard.getButtonElement("ם").onclick();
expect(keyboard.getInput()).toBe("‫שום‬");
const input = document.createElement("input");
input.value = keyboard.getInput();
input.type = "text";
input.selectionStart = 2;
input.selectionEnd = 2;
keyboard.caretEventHandler({
type: "selectionchange",
target: input
});
expect(caretEventHandler).toHaveBeenCalled();
expect(keyboard.getCaretPosition()).toBe(1);
keyboard.getButtonElement("ל").onclick();
expect(keyboard.getInput()).toBe('‫שלום‬');
input.value = keyboard.getInput();
input.type = "text";
input.selectionStart = 4;
input.selectionEnd = 4;
keyboard.caretEventHandler({
type: "selectionchange",
target: input
});
keyboard.getButtonElement("{bksp}").onclick();
expect(keyboard.getInput()).toBe('‫שלם‬');
});