mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2026-04-30 00:00:04 +08:00
Address upgrade issues
This commit is contained in:
@@ -27,7 +27,6 @@ class SimpleKeyboard {
|
||||
*/
|
||||
this.utilities = new Utilities({
|
||||
getOptions: this.getOptions,
|
||||
setCaretPosition: this.setCaretPosition,
|
||||
getCaretPosition: this.getCaretPosition,
|
||||
getCaretPositionEnd: this.getCaretPositionEnd,
|
||||
dispatch: this.dispatch
|
||||
@@ -231,10 +230,10 @@ class SimpleKeyboard {
|
||||
/**
|
||||
* Setters
|
||||
*/
|
||||
setCaretPosition = (position, endPosition) => {
|
||||
setCaretPosition(position, endPosition) {
|
||||
this.caretPosition = position;
|
||||
this.caretPositionEnd = endPosition || position;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles clicks made to keyboard buttons
|
||||
@@ -544,10 +543,10 @@ class SimpleKeyboard {
|
||||
/**
|
||||
* inputName changed. This requires a caretPosition reset
|
||||
*/
|
||||
// TODO: Review side-effects
|
||||
if (this.options.debug) {
|
||||
console.log("inputName changed. caretPosition reset.");
|
||||
}
|
||||
|
||||
this.setCaretPosition(null);
|
||||
}
|
||||
}
|
||||
@@ -873,6 +872,8 @@ class SimpleKeyboard {
|
||||
`(${instance.keyboardDOMClass})`
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Review side-effects
|
||||
} else if (!isKeyboard) {
|
||||
instance.setCaretPosition(null);
|
||||
}
|
||||
|
||||
@@ -5,17 +5,10 @@ class Utilities {
|
||||
/**
|
||||
* Creates an instance of the Utility service
|
||||
*/
|
||||
constructor({
|
||||
getOptions,
|
||||
setCaretPosition,
|
||||
getCaretPosition,
|
||||
getCaretPositionEnd,
|
||||
dispatch
|
||||
}) {
|
||||
constructor({ getOptions, getCaretPosition, getCaretPositionEnd, dispatch }) {
|
||||
this.getOptions = getOptions;
|
||||
this.getCaretPosition = getCaretPosition;
|
||||
this.getCaretPositionEnd = getCaretPositionEnd;
|
||||
this.setCaretPosition = setCaretPosition;
|
||||
this.dispatch = dispatch;
|
||||
|
||||
/**
|
||||
@@ -203,15 +196,10 @@ class Utilities {
|
||||
*/
|
||||
updateCaretPos(length, minus) {
|
||||
const newCaretPos = this.updateCaretPosAction(length, minus);
|
||||
const { syncInstanceInputs } = this.getOptions();
|
||||
|
||||
if (syncInstanceInputs) {
|
||||
this.dispatch(instance => {
|
||||
instance.setCaretPosition(newCaretPos);
|
||||
});
|
||||
} else {
|
||||
this.setCaretPosition(newCaretPos);
|
||||
}
|
||||
this.dispatch(instance => {
|
||||
instance.setCaretPosition(newCaretPos);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,8 +273,6 @@ class Utilities {
|
||||
positionEnd = source.length,
|
||||
moveCaret = false
|
||||
) {
|
||||
const { syncInstanceInputs } = this.getOptions();
|
||||
|
||||
if (position === 0 && positionEnd === 0) {
|
||||
return source;
|
||||
}
|
||||
@@ -328,13 +314,9 @@ class Utilities {
|
||||
} else {
|
||||
output = source.slice(0, position) + source.slice(positionEnd);
|
||||
if (moveCaret) {
|
||||
if (syncInstanceInputs) {
|
||||
this.dispatch(instance => {
|
||||
instance.setCaretPosition(position);
|
||||
});
|
||||
} else {
|
||||
this.setCaretPosition(position);
|
||||
}
|
||||
this.dispatch(instance => {
|
||||
instance.setCaretPosition(position);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -490,11 +490,11 @@ it('Keyboard removeAt will propagate caretPosition', () => {
|
||||
keyboard.getButtonElement('{bksp}').onclick();
|
||||
|
||||
expect(keyboard.getCaretPosition()).toBe(1);
|
||||
expect(keyboard2.getCaretPosition()).toBe(null);
|
||||
expect(keyboard2.getCaretPosition()).toBe(1);
|
||||
|
||||
expect(keyboard.getInput()).toBe('hlo');
|
||||
expect(keyboard.getCaretPositionEnd()).toBe(1);
|
||||
expect(keyboard2.getCaretPositionEnd()).toBe(null);
|
||||
expect(keyboard2.getCaretPositionEnd()).toBe(1);
|
||||
});
|
||||
|
||||
it('Keyboard removeAt will propagate caretPosition in a syncInstanceInputs setting', () => {
|
||||
|
||||
Reference in New Issue
Block a user