diff --git a/prefs/zen-urlbar.yaml b/prefs/zen-urlbar.yaml index b9b0533d4f..fcefe8a1b1 100644 --- a/prefs/zen-urlbar.yaml +++ b/prefs/zen-urlbar.yaml @@ -11,6 +11,9 @@ - name: zen.urlbar.behavior value: floating-on-type +- name: zen.urlbar.vim-navigation.enabled + value: false + - name: zen.urlbar.wait-to-clear value: 45000 diff --git a/src/browser/components/preferences/zen-settings.js b/src/browser/components/preferences/zen-settings.js index a93ba5b460..9f738c2045 100644 --- a/src/browser/components/preferences/zen-settings.js +++ b/src/browser/components/preferences/zen-settings.js @@ -1130,6 +1130,11 @@ Preferences.addAll([ type: 'string', default: 'float', }, + { + id: 'zen.urlbar.vim-navigation.enabled', + type: 'bool', + default: false, + }, { id: 'zen.workspaces.separate-essentials', type: 'bool', diff --git a/src/browser/components/urlbar/UrlbarController-sys-mjs.patch b/src/browser/components/urlbar/UrlbarController-sys-mjs.patch index 3ebb104aea..393a379b8c 100644 --- a/src/browser/components/urlbar/UrlbarController-sys-mjs.patch +++ b/src/browser/components/urlbar/UrlbarController-sys-mjs.patch @@ -2,6 +2,27 @@ diff --git a/browser/components/urlbar/UrlbarController.sys.mjs b/browser/compon index 36e3ab4a5a153230bb488b66dda7e3e7c763ca23..cc4ea61914a316451fa54b01a5c8c6a305e4038a 100644 --- a/browser/components/urlbar/UrlbarController.sys.mjs +++ b/browser/components/urlbar/UrlbarController.sys.mjs +@@ -302,6 +302,20 @@ export class UrlbarController { + return; + } + ++ // Handle vim navigation bindings. ++ if ( ++ this.view.isOpen && ++ event.ctrlKey && ++ (event.key == "j" || event.key == "k") && ++ Services.prefs.getBoolPref("zen.urlbar.vim-navigation.enabled", false) ++ ) { ++ if (executeAction) { ++ this.view.selectBy(1, { reverse: event.key == "k" }); ++ } ++ event.preventDefault(); ++ return; ++ } ++ + if (this.view.isOpen && executeAction && this._lastQueryContextWrapper) { + // In native inputs on most platforms, Shift+Up/Down moves the caret to the + // start/end of the input and changes its selection, so in that case defer @@ -434,6 +434,8 @@ export class UrlbarController { }); } diff --git a/src/zen/tests/urlbar/browser.toml b/src/zen/tests/urlbar/browser.toml index c451b796e7..9236a1483f 100644 --- a/src/zen/tests/urlbar/browser.toml +++ b/src/zen/tests/urlbar/browser.toml @@ -10,3 +10,4 @@ support-files = [ ["browser_floating_urlbar.js"] ["browser_issue_7385.js"] +["browser_vim_navigation.js"] diff --git a/src/zen/tests/urlbar/browser_vim_navigation.js b/src/zen/tests/urlbar/browser_vim_navigation.js new file mode 100644 index 0000000000..a075535fb5 --- /dev/null +++ b/src/zen/tests/urlbar/browser_vim_navigation.js @@ -0,0 +1,71 @@ +/* Any copyright is dedicated to the Public Domain. + https://creativecommons.org/publicdomain/zero/1.0/ */ + +'use strict'; + +ChromeUtils.defineESModuleGetters(this, { + UrlbarTestUtils: 'resource://testing-common/UrlbarTestUtils.sys.mjs', +}); + +add_task(async function test_Vim_Navigation_on() { + gURLBar.blur(); + + await SpecialPowers.pushPrefEnv({ + set: [['zen.urlbar.vim-navigation.enabled', true]], + }); + + await SimpleTest.promiseFocus(window); + document.getElementById('Browser:OpenLocation').doCommand(); + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + waitForFocus: SimpleTest.waitForFocus, + // This value yields several results in the urlbar + value: 'a', + }); + + // Ctrl+j and down should work to move the selection down + EventUtils.synthesizeKey('j', { ctrlKey: true }, window); + // Move down one more time so the next assertion doesn't land on the start + EventUtils.synthesizeKey('j', { ctrlKey: true }, window); + EventUtils.synthesizeKey('VK_DOWN', {}, window); + + ok( + UrlbarTestUtils.getSelectedRowIndex(window) == 3, + 'Ctrl+j and down should change the selection' + ); + + // Ctrl+k and up should work to move the selection up + EventUtils.synthesizeKey('k', { ctrlKey: true }, window); + EventUtils.synthesizeKey('VK_UP', {}, window); + ok(UrlbarTestUtils.getSelectedRowIndex(window) == 1, 'Ctrl+k and up should change the selection'); +}); + +add_task(async function test_Vim_Navigation_off() { + gURLBar.blur(); + + await SpecialPowers.pushPrefEnv({ + set: [['zen.urlbar.vim-navigation.enabled', false]], + }); + + await SimpleTest.promiseFocus(window); + document.getElementById('Browser:OpenLocation').doCommand(); + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + waitForFocus: SimpleTest.waitForFocus, + // This value yields several results in the urlbar + value: 'a', + }); + + // Only down should work to move the selection down + EventUtils.synthesizeKey('j', { ctrlKey: true }, window); + EventUtils.synthesizeKey('j', { ctrlKey: true }, window); + EventUtils.synthesizeKey('VK_DOWN', {}, window); + EventUtils.synthesizeKey('VK_DOWN', {}, window); + + ok(UrlbarTestUtils.getSelectedRowIndex(window) == 2, 'Only down should change the selection'); + + // Only up should work to move the selection up + EventUtils.synthesizeKey('k', { ctrlKey: true }, window); + EventUtils.synthesizeKey('VK_UP', {}, window); + ok(UrlbarTestUtils.getSelectedRowIndex(window) == 1, 'Only up should change the selection'); +});