Skip to content
Open
3 changes: 3 additions & 0 deletions prefs/zen-urlbar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/browser/components/preferences/zen-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions src/browser/components/urlbar/UrlbarController-sys-mjs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
});
}
Expand Down
1 change: 1 addition & 0 deletions src/zen/tests/urlbar/browser.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ support-files = [

["browser_floating_urlbar.js"]
["browser_issue_7385.js"]
["browser_vim_navigation.js"]
71 changes: 71 additions & 0 deletions src/zen/tests/urlbar/browser_vim_navigation.js
Original file line number Diff line number Diff line change
@@ -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');
});