Bug 1481443 - Disable Alt-B & Alt-F shortcut in source editor; r=gl.
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Tue, 21 Aug 2018 12:29:00 +0000
changeset 487752 20a3b24e500abc7bf403466c8beb8c38abbaeb6a
parent 487751 f168924d45d2346aaaa19b34360692282bba9e9f
child 487753 ed07516ab49e79cdfaf85785bc8f572aee1de55a
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgl
bugs1481443
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1481443 - Disable Alt-B & Alt-F shortcut in source editor; r=gl. Without this patch, hitting Alt-B was adding a character **and** moving the cursor to the previous group, while Alt-F was also adding a character **and** moving the cursor to the next group. We disable the shortcut to fix this and add a test to make sure we don't regress. Differential Revision: https://phabricator.services.mozilla.com/D2918
devtools/client/sourceeditor/editor.js
devtools/client/sourceeditor/test/browser.ini
devtools/client/sourceeditor/test/browser_editor_alt_b_f.js
--- a/devtools/client/sourceeditor/editor.js
+++ b/devtools/client/sourceeditor/editor.js
@@ -145,16 +145,22 @@ function Editor(config) {
   this.config.extraKeys[Editor.keyFor("moveLineDown", { noaccel: true })] =
     () => this.moveLineDown();
   this.config.extraKeys[Editor.keyFor("toggleComment")] = "toggleComment";
 
   // Disable ctrl-[ and ctrl-] because toolbox uses those shortcuts.
   this.config.extraKeys[Editor.keyFor("indentLess")] = false;
   this.config.extraKeys[Editor.keyFor("indentMore")] = false;
 
+  // Disable Alt-B and Alt-F to navigate groups (respectively previous and next) since:
+  // - it's not standard in input fields
+  // - it also inserts a character which feels weird
+  this.config.extraKeys["Alt-B"] = false;
+  this.config.extraKeys["Alt-F"] = false;
+
   // Overwrite default config with user-provided, if needed.
   Object.keys(config).forEach(k => {
     if (k != "extraKeys") {
       this.config[k] = config[k];
       return;
     }
 
     if (!config.extraKeys) {
--- a/devtools/client/sourceeditor/test/browser.ini
+++ b/devtools/client/sourceeditor/test/browser.ini
@@ -25,16 +25,17 @@ support-files =
   cm_mode_ruby.js
   cm_script_injection_test.js
   !/devtools/client/shared/test/shared-head.js
   !/devtools/client/shared/test/telemetry-test-helpers.js
 
 [browser_editor_autocomplete_basic.js]
 [browser_editor_autocomplete_events.js]
 [browser_editor_autocomplete_js.js]
+[browser_editor_alt_b_f.js]
 [browser_editor_basic.js]
 [browser_editor_cursor.js]
 [browser_editor_find_again.js]
 [browser_editor_goto_line.js]
 [browser_editor_history.js]
 [browser_editor_markers.js]
 [browser_editor_movelines.js]
 [browser_editor_prefs.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/sourceeditor/test/browser_editor_alt_b_f.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Ensure Alt-B and Alt-F keyboard shortcuts work as expected in the source editor.
+// See Bug 1481443.
+
+add_task(async function() {
+  const {ed, win} = await setup();
+  const editorDoc = ed.container.contentDocument;
+  await promiseWaitForFocus();
+  const isMacOS = Services.appinfo.OS === "Darwin";
+
+  ed.focus();
+
+  const initialText = "a b c d e";
+  ed.setText(initialText);
+
+  ed.setCursor({ line: 1, ch: initialText.length });
+
+  EventUtils.synthesizeKey("b", { altKey: true }, editorDoc.defaultView);
+
+  // A character is added only on OSX.
+  let expectedText = isMacOS ? initialText + "b" : initialText;
+  is(ed.getCursor().ch, expectedText.length,
+    "Cursor is at expected position after Alt-B");
+  is(ed.getText(), expectedText, "Editor has expected content after Alt-B");
+
+  EventUtils.synthesizeKey("f", { altKey: true }, editorDoc.defaultView);
+
+  // A character is added only on OSX.
+  expectedText = isMacOS ? expectedText + "f" : initialText;
+  is(ed.getCursor().ch, expectedText.length,
+    "Cursor is at expected position after Alt-F");
+  is(ed.getText(), expectedText, "Editor has expected content after Alt-F");
+
+  ed.destroy();
+  win.close();
+});