mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 17:25:36 +00:00
Bug 1505024 - Disable codeMirror search addon in JsTerm; r=Honza.
This patches fixes a bug where hitting Cmd+F while the filter input of the console was focused was triggering codeMirror search addon, displaying the search UI *in* JsTerm. To prevent this, we add the ability for any consumer of the Editor component to disable the search addon. In the editor, in such case, we simply don't initialize the event listeners that activate the search addon. A test case is added to ensure we don't regress this. Differential Revision: https://phabricator.services.mozilla.com/D11037 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
b9502d4724
commit
4023106c5a
@ -136,6 +136,8 @@ function Editor(config) {
|
||||
themeSwitching: true,
|
||||
autocomplete: false,
|
||||
autocompleteOpts: {},
|
||||
// Set to true to prevent the search addon to be activated.
|
||||
disableSearchAddon: false,
|
||||
};
|
||||
|
||||
// Additional shortcuts.
|
||||
@ -438,7 +440,9 @@ Editor.prototype = {
|
||||
return L10N.getStr(name);
|
||||
});
|
||||
|
||||
this._initShortcuts(win);
|
||||
if (!this.config.disableSearchAddon) {
|
||||
this._initSearchShortcuts(win);
|
||||
}
|
||||
|
||||
editors.set(this, cm);
|
||||
|
||||
@ -1398,11 +1402,11 @@ Editor.prototype = {
|
||||
/**
|
||||
* Register all key shortcuts.
|
||||
*/
|
||||
_initShortcuts: function(win) {
|
||||
_initSearchShortcuts: function(win) {
|
||||
const shortcuts = new KeyShortcuts({
|
||||
window: win,
|
||||
});
|
||||
this._onShortcut = this._onShortcut.bind(this);
|
||||
this._onSearchShortcut = this._onSearchShortcut.bind(this);
|
||||
const keys = [
|
||||
"find.key",
|
||||
"findNext.key",
|
||||
@ -1417,13 +1421,13 @@ Editor.prototype = {
|
||||
// Process generic keys:
|
||||
keys.forEach(name => {
|
||||
const key = L10N.getStr(name);
|
||||
shortcuts.on(key, event => this._onShortcut(name, event));
|
||||
shortcuts.on(key, event => this._onSearchShortcut(name, event));
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Key shortcut listener.
|
||||
*/
|
||||
_onShortcut: function(name, event) {
|
||||
_onSearchShortcut: function(name, event) {
|
||||
if (!this._isInputOrTextarea(event.target)) {
|
||||
return;
|
||||
}
|
||||
|
@ -200,6 +200,7 @@ class JSTerm extends Component {
|
||||
styleActiveLine: false,
|
||||
tabIndex: "0",
|
||||
viewportMargin: Infinity,
|
||||
disableSearchAddon: true,
|
||||
extraKeys: {
|
||||
"Enter": () => {
|
||||
// No need to handle shift + Enter as it's natively handled by CodeMirror.
|
||||
|
@ -19,14 +19,14 @@ const TEST_URI =
|
||||
add_task(async function() {
|
||||
// Run in legacy JsTerm.
|
||||
await pushPref("devtools.webconsole.jsterm.codeMirror", false);
|
||||
await testHistory();
|
||||
await performTests();
|
||||
|
||||
// And then in codeMirror JsTerm.
|
||||
await pushPref("devtools.webconsole.jsterm.codeMirror", true);
|
||||
await testHistory();
|
||||
await performTests();
|
||||
});
|
||||
|
||||
async function testHistory() {
|
||||
async function performTests() {
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
info("Web Console opened");
|
||||
const outputScroller = hud.ui.outputScroller;
|
||||
@ -70,6 +70,11 @@ async function testHistory() {
|
||||
info("try ctrl-f to focus filter");
|
||||
synthesizeKeyShortcut(WCUL10n.getStr("webconsole.find.key"));
|
||||
ok(!isJstermFocused(hud.jsterm), "jsterm input is not focused");
|
||||
ok(hasFocus(hud.ui.filterBox), "filter input is focused");
|
||||
|
||||
info("try ctrl-f when filter is already focused");
|
||||
synthesizeKeyShortcut(WCUL10n.getStr("webconsole.find.key"));
|
||||
ok(!isJstermFocused(hud.jsterm), "jsterm input is not focused");
|
||||
is(hud.ui.filterBox, outputScroller.ownerDocument.activeElement,
|
||||
"filter input is focused");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user