mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-01-20 01:22:59 +08:00
SyncInstanceInputs caret position and tests improvements. Fixes #65
This commit is contained in:
parent
049900b49a
commit
1b55cbe774
@ -296,6 +296,7 @@ class SimpleKeyboard {
|
|||||||
syncInstanceInputs() {
|
syncInstanceInputs() {
|
||||||
this.dispatch(instance => {
|
this.dispatch(instance => {
|
||||||
instance.replaceInput(this.input);
|
instance.replaceInput(this.input);
|
||||||
|
instance.caretPosition = this.caretPosition;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,11 +355,6 @@ class SimpleKeyboard {
|
|||||||
*/
|
*/
|
||||||
replaceInput(inputObj) {
|
replaceInput(inputObj) {
|
||||||
this.input = inputObj;
|
this.input = inputObj;
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset caretPosition
|
|
||||||
*/
|
|
||||||
this.caretPosition = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -168,6 +168,26 @@ it('Keyboard syncInstanceInputs will work', () => {
|
|||||||
keyboard1.getButtonElement("q").onclick();
|
keyboard1.getButtonElement("q").onclick();
|
||||||
|
|
||||||
expect(keyboard2.getInput()).toBe("q");
|
expect(keyboard2.getInput()).toBe("q");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test cursor syncing...
|
||||||
|
* Reinit keyboards
|
||||||
|
*/
|
||||||
|
keyboard1 = new Keyboard(".keyboard1", sharedOptions);
|
||||||
|
keyboard2 = new Keyboard(".keyboard2", sharedOptions);
|
||||||
|
|
||||||
|
keyboard1.getButtonElement("1").onclick();
|
||||||
|
keyboard1.getButtonElement("5").onclick();
|
||||||
|
keyboard1.getButtonElement("6").onclick();
|
||||||
|
|
||||||
|
keyboard1.caretPosition = 1;
|
||||||
|
|
||||||
|
keyboard1.getButtonElement("2").onclick();
|
||||||
|
keyboard1.getButtonElement("3").onclick();
|
||||||
|
keyboard1.getButtonElement("4").onclick();
|
||||||
|
|
||||||
|
expect(keyboard1.getInput()).toBe("123456");
|
||||||
|
expect(keyboard2.getInput()).toBe("123456");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Keyboard onChange will work', () => {
|
it('Keyboard onChange will work', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user