reuse setInputValue
This commit is contained in:
parent
ef998e423e
commit
48d90544f6
13
edit/base.js
13
edit/base.js
|
@ -1,4 +1,4 @@
|
||||||
/* global $$ $ $create messageBoxProxy setupLivePrefs */// dom.js
|
/* global $$ $ $create messageBoxProxy setInputValue setupLivePrefs */// dom.js
|
||||||
/* global API */// msg.js
|
/* global API */// msg.js
|
||||||
/* global CODEMIRROR_THEMES */
|
/* global CODEMIRROR_THEMES */
|
||||||
/* global CodeMirror */
|
/* global CodeMirror */
|
||||||
|
@ -136,15 +136,8 @@ function EditorHeader() {
|
||||||
});
|
});
|
||||||
resetEl.hidden = !editor.style.customName;
|
resetEl.hidden = !editor.style.customName;
|
||||||
resetEl.onclick = () => {
|
resetEl.onclick = () => {
|
||||||
const {style} = editor;
|
editor.style.customName = null; // to delete it from db
|
||||||
nameEl.focus();
|
setInputValue(nameEl, editor.style.name);
|
||||||
nameEl.select();
|
|
||||||
// trying to make it undoable via Ctrl-Z
|
|
||||||
if (!document.execCommand('insertText', false, style.name)) {
|
|
||||||
nameEl.value = style.name;
|
|
||||||
editor.updateName(true);
|
|
||||||
}
|
|
||||||
style.customName = null; // to delete it from db
|
|
||||||
resetEl.hidden = true;
|
resetEl.hidden = true;
|
||||||
};
|
};
|
||||||
const enabledEl = $('#enabled');
|
const enabledEl = $('#enabled');
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* global $ $$ $create $remove focusAccessibility toggleDataset */// dom.js
|
/* global $ $$ $create $remove focusAccessibility setInputValue toggleDataset */// dom.js
|
||||||
/* global CodeMirror */
|
/* global CodeMirror */
|
||||||
/* global chromeLocal */// storage-util.js
|
/* global chromeLocal */// storage-util.js
|
||||||
/* global colorMimicry */
|
/* global colorMimicry */
|
||||||
|
@ -930,18 +930,5 @@
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
//endregion
|
||||||
})();
|
})();
|
||||||
|
|
13
js/dom.js
13
js/dom.js
|
@ -13,6 +13,7 @@
|
||||||
messageBoxProxy
|
messageBoxProxy
|
||||||
moveFocus
|
moveFocus
|
||||||
scrollElementIntoView
|
scrollElementIntoView
|
||||||
|
setInputValue
|
||||||
setupLivePrefs
|
setupLivePrefs
|
||||||
showSpinner
|
showSpinner
|
||||||
toggleDataset
|
toggleDataset
|
||||||
|
@ -296,6 +297,18 @@ function scrollElementIntoView(element, {invalidMarginRatio = 0} = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accepts an array of pref names (values are fetched via prefs.get)
|
* Accepts an array of pref names (values are fetched via prefs.get)
|
||||||
* and establishes a two-way connection between the document elements and the actual prefs
|
* and establishes a two-way connection between the document elements and the actual prefs
|
||||||
|
|
Loading…
Reference in New Issue
Block a user