FF execCommand bug workaround needs 'input' event dispatched

fixes #419
This commit is contained in:
tophf 2018-07-06 12:37:35 +03:00
parent c09f7c341c
commit 796b2b132d

View File

@ -93,11 +93,7 @@ onDOMready().then(() => {
replaceAll: () => doReplaceAll(), replaceAll: () => doReplaceAll(),
undo: () => doUndo(), undo: () => doUndo(),
clear() { clear() {
this._input.focus(); setInputValue(this._input, '');
document.execCommand('selectAll', false, null);
document.execCommand('delete', false, null);
// some versions of Firefox ignore the above
this._input.value = '';
}, },
case() { case() {
state.icase = !state.icase; state.icase = !state.icase;
@ -545,11 +541,7 @@ onDOMready().then(() => {
destroyDialog(); destroyDialog();
createDialog(type); createDialog(type);
} else if (sel) { } else if (sel) {
state.input.focus(); setInputValue(state.input, sel);
state.input.select();
document.execCommand('insertText', false, sel);
// some versions of Firefox ignore the above
state.input.value = sel;
} }
state.input.focus(); state.input.focus();
@ -933,4 +925,19 @@ onDOMready().then(() => {
}) })
})); }));
} }
function setInputValue(input, value) {
input.focus();
input.select();
// using execCommand to add to the input's undo history
document.execCommand(value ? 'insertText' : 'delete', false, value);
// some versions of Firefox ignore execCommand
if (input.value !== value) {
input.value = value;
input.dispatchEvent(new Event('input', {bubbles: true}));
}
}
//endregion
}); });