Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions background_scripts/completion/all_completers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const completerNames = ["omni", "bookmarks", "tabs"];
2 changes: 1 addition & 1 deletion background_scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const completionSources = {
searchEngines: new SearchEngineCompleter(),
};

const completers = {
export const completers = {
omni: new MultiCompleter([
completionSources.bookmarks,
completionSources.history,
Expand Down
31 changes: 26 additions & 5 deletions pages/vomnibar_page.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,39 @@ ul {
z-index: 2139999999;
}

#vomnibar input {
#vomnibar-search-area * {
font-size: 20px;
height: 34px;
margin-bottom: 0;
padding: 4px;
background-color: white;
color: black;
border-radius: 3px;
border: 1px solid #e8e8e8;
box-shadow: #444 0px 0px 1px;
width: 100%;
outline: none;
box-sizing: border-box;
}

#vomnibar #completer-name {
margin-right: 8px;
font-size: 12px;
display: flex;
align-items: center;
background: unset;
color: #990000;
}

#vomnibar-search-area .mode:empty {
display: none;
}

#vomnibar-search-area input {
background-color: white;
color: black;
width: 100%;
}

#vomnibar-search-area {
display: block;
display: flex;
padding: 10px;
border-radius: 4px 4px 0 0;
border-bottom: 1px solid #c6c9ce;
Expand Down Expand Up @@ -149,6 +165,11 @@ ul {
border-bottom: 1px solid var(--vimium-foreground-color);
}

#vomnibar-search-area #completer-name {
color: #999000;
border: 1px solid var(--vimium-foreground-color);
}

#vomnibar input {
background-color: var(--vimium-foreground-color);
color: var(--vimium-foreground-text-color);
Expand Down
1 change: 1 addition & 0 deletions pages/vomnibar_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<body>
<div id="vomnibar">
<div id="vomnibar-search-area">
<span id="completer-name"></span>
<input type="text" autocomplete="off">
</div>
<ul></ul>
Expand Down
25 changes: 25 additions & 0 deletions pages/vomnibar_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "../lib/dom_utils.js";
import "../lib/handler_stack.js";
import * as UIComponentMessenger from "./ui_component_messenger.js";
import * as userSearchEngines from "../background_scripts/user_search_engines.js";
import { completerNames } from "../background_scripts/completion/all_completers.js";

export let ui; // An instance of VomnibarUI.

Expand Down Expand Up @@ -98,6 +99,7 @@ class VomnibarUI {
hide(onHiddenCallback = null) {
this.onHiddenCallback = onHiddenCallback;
this.input.blur();
this.label.textContent = "";
this.reset();
// Wait until this iframe's DOM has been rendered before hiding the iframe. This is to prevent
// Chrome caching the previous visual state of the vomnibar iframe. See #4708.
Expand Down Expand Up @@ -178,6 +180,12 @@ class VomnibarUI {
return "remove";
} else if (KeyboardUtils.isBackspace(event)) {
return "delete";
} else if (event.altKey && key == "m") {
return "cycle-completer-next";
} else if (event.altKey && key == "M") {
return "cycle-completer-prev";
} else if (event.altKey && key == "n") {
return "switch-new-tab";
}

return null;
Expand Down Expand Up @@ -243,6 +251,18 @@ class VomnibarUI {
} else if ((action === "remove") && (this.selection >= 0)) {
const completion = this.completions[this.selection];
console.log(completion);
} else if (action == "cycle-completer-next") {
const size = completerNames.length;
this.completerName = completerNames[(completerNames.indexOf(this.completerName) + 1) % size];
this.update();
} else if (action == "cycle-completer-prev") {
const size = completerNames.length;
this.completerName =
completerNames[(completerNames.indexOf(this.completerName) + size - 1) % size];
this.update();
} else if (action == "switch-new-tab" && this.completerName != "tabs") {
this.forceNewTab = !this.forceNewTab;
this.update();
}

event.stopImmediatePropagation();
Expand Down Expand Up @@ -397,6 +417,10 @@ class VomnibarUI {
}

async update() {
this.label.textContent = this.completerName.toUpperCase();
if (this.forceNewTab) {
this.label.textContent += "\u00A0+";
}
await this.updateCompletions();
this.input.focus();
}
Expand Down Expand Up @@ -424,6 +448,7 @@ class VomnibarUI {
initDom() {
this.box = document.getElementById("vomnibar");

this.label = document.getElementById("completer-name");
this.input = this.box.querySelector("input");
this.input.addEventListener("input", this.onInput);
this.input.addEventListener("keydown", this.onKeyEvent);
Expand Down
8 changes: 8 additions & 0 deletions tests/unit_tests/completion/completers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
import * as ranking from "../../../background_scripts/completion/ranking.js";
import { RegexpCache } from "../../../background_scripts/completion/ranking.js";
import "../../../lib/url_utils.js";
import { completers } from "../../../background_scripts/main.js";
import { completerNames } from "../../../background_scripts/completion/all_completers.js";

const hours = (n) => 1000 * 60 * 60 * n;

Expand All @@ -28,6 +30,12 @@ const filterCompleter = async (completer, queryTerms) => {
});
};

context("completer list", () => {
should("define all completers", () => {
assert.equal(Object.keys(completers), completerNames);
});
});

context("bookmark completer", () => {
const bookmark3 = { title: "bookmark3", url: "bookmark3.com" };
const bookmark2 = { title: "bookmark2", url: "bookmark2.com" };
Expand Down