mirror of
https://github.com/hodgef/simple-keyboard.git
synced 2025-01-19 08:32:57 +08:00
Address upgrade issues
This commit is contained in:
parent
44cdc2bbb0
commit
fd0c48390d
@ -77,9 +77,9 @@ Want to create your own module? Check out the [Modules page](https://hodgef.com/
|
||||
> Simple-keyboard is intended for modern, standards-compliant browsers.
|
||||
> Internet Explorer is sadly not one of them, and since its market-share is negligible (~2% for IE11), resources won't be spent in trying to support it.
|
||||
>
|
||||
> To learn more about the rationale for not supporting IE, check out [this link](https://techcommunity.microsoft.com/t5/Windows-IT-Pro-Blog/The-perils-of-using-Internet-Explorer-as-your-default-browser/ba-p/331732).
|
||||
> For more information, check out [this Q&A entry](https://hodgef.com/simple-keyboard/questions-answers/internet-explorer-not-supported/).
|
||||
|
||||
## Contributing ✅
|
||||
|
||||
PR's and issues are welcome. Feel free to submit any issues you have at:
|
||||
PRs and issues are always welcome. Feel free to submit any issues you have at:
|
||||
[https://github.com/hodgef/simple-keyboard/issues](https://github.com/hodgef/simple-keyboard/issues)
|
||||
|
@ -4,10 +4,10 @@ import "./css/index.css";
|
||||
* Demos
|
||||
*/
|
||||
import BasicDemo from "./BasicDemo";
|
||||
// import ButtonThemeDemo from "./ButtonThemeDemo";
|
||||
// import DOMElementDemo from "./DOMElementDemo";
|
||||
// import FullKeyboardDemo from "./FullKeyboardDemo";
|
||||
// import MultipleKeyboardsDemo from "./MultipleKeyboardsDestroyDemo";
|
||||
//import ButtonThemeDemo from "./ButtonThemeDemo";
|
||||
//import DOMElementDemo from "./DOMElementDemo";
|
||||
//import FullKeyboardDemo from "./FullKeyboardDemo";
|
||||
//import MultipleKeyboardsDemo from "./MultipleKeyboardsDestroyDemo";
|
||||
|
||||
/**
|
||||
* Selected demo
|
||||
|
@ -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', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user