mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-04-11 00:02:15 +08:00
Address caret positioning issues. Fixes https://github.com/hodgef/simple-keyboard/issues/695 - Fixes https://github.com/hodgef/react-simple-keyboard/issues/788
This commit is contained in:
@@ -590,13 +590,15 @@ it('Keyboard will receive physical keyboard events', () => {
|
||||
physicalKeyboardHighlight: true
|
||||
});
|
||||
|
||||
document.onkeyup({
|
||||
document.dispatchEvent(new KeyboardEvent('keyup', {
|
||||
charCode: 0,
|
||||
code: "KeyF",
|
||||
key: "f",
|
||||
which: 70,
|
||||
target: document.createElement('input')
|
||||
});
|
||||
target: {
|
||||
tagName: "input"
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
it('Keyboard caretEventHandler will detect input, textarea focus', () => {
|
||||
@@ -1224,15 +1226,15 @@ it('Keyboard destroy will work', () => {
|
||||
expect(document.onkeydown).toBe(null);
|
||||
expect(document.onkeyup).toBe(null);
|
||||
|
||||
expect(document.onpointerdown).toBe(null);
|
||||
expect(document.onpointerup).toBe(null);
|
||||
// expect(document.onpointerdown).toBe(null);
|
||||
// expect(document.onpointerup).toBe(null);
|
||||
|
||||
expect(document.onmousedown).toBe(null);
|
||||
expect(document.onmouseup).toBe(null);
|
||||
// expect(document.onmousedown).toBe(null);
|
||||
// expect(document.onmouseup).toBe(null);
|
||||
|
||||
expect(document.ontouchstart).toBe(null);
|
||||
expect(document.ontouchend).toBe(null);
|
||||
expect(document.ontouchcancel).toBe(null);
|
||||
// expect(document.ontouchstart).toBe(null);
|
||||
// expect(document.ontouchend).toBe(null);
|
||||
// expect(document.ontouchcancel).toBe(null);
|
||||
|
||||
expect(keyboard.initialized).toBe(false);
|
||||
});
|
||||
@@ -1262,10 +1264,8 @@ it('Keyboard caretEventHandler will be triggered on mouseup and ontouchend', ()
|
||||
disableCaretPositioning: true
|
||||
});
|
||||
|
||||
// TODO: Will need further investigation
|
||||
// https://github.com/hodgef/simple-keyboard/issues/54
|
||||
// keyboard.setCaretPosition(6);
|
||||
// expect(keyboard.getCaretPosition()).toBe(6);
|
||||
keyboard.setCaretPosition(6);
|
||||
expect(keyboard.getCaretPosition()).toBe(6);
|
||||
|
||||
const event = {
|
||||
target: document.body
|
||||
@@ -1381,17 +1381,32 @@ it('Keyboard handleKeyboardContainerMouseDown will respect preventMouseDownDefau
|
||||
expect(works).toBe(true);
|
||||
});
|
||||
|
||||
it('Keyboard handlePointerDown will work', () => {
|
||||
it('Keyboard caret positioning will work', () => {
|
||||
setDOM();
|
||||
|
||||
const keyboard = new Keyboard();
|
||||
const keyboard = new Keyboard({
|
||||
onKeyPress: (button) => {
|
||||
if (button === "{shift}" || button === "{lock}") handleShift();
|
||||
else if (keyboard.options.layoutName === "shift") handleShift();
|
||||
}
|
||||
});
|
||||
|
||||
keyboard.setCaretPosition(3);
|
||||
expect(keyboard.getCaretPosition()).toBe(3);
|
||||
function handleShift() {
|
||||
const currentLayout = keyboard.options.layoutName;
|
||||
const shiftToggle = currentLayout === "default" ? "shift" : "default";
|
||||
|
||||
keyboard.setOptions({
|
||||
layoutName: shiftToggle
|
||||
});
|
||||
}
|
||||
|
||||
triggerDocumentPointerDown({
|
||||
target: document.body
|
||||
})
|
||||
keyboard.getButtonElement("h").onpointerdown();
|
||||
keyboard.getButtonElement("o").onpointerdown();
|
||||
keyboard.setCaretPosition(1);
|
||||
keyboard.getButtonElement("{shift}")[0].onpointerdown();
|
||||
keyboard.getButtonElement("E").onpointerdown();
|
||||
keyboard.getButtonElement("l").onpointerdown();
|
||||
keyboard.getButtonElement("l").onpointerdown();
|
||||
|
||||
expect(keyboard.getCaretPosition()).toBe(null);
|
||||
expect(keyboard.getInput()).toBe("hEllo");
|
||||
});
|
||||
Reference in New Issue
Block a user