Skip to content

Commit 47927fc

Browse files
committed
Merge remote-tracking branch 'origin/master' into feat/move-tab-to-existing-window
2 parents cf11b0e + 445486e commit 47927fc

File tree

14 files changed

+87
-122
lines changed

14 files changed

+87
-122
lines changed

.gitignore

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
*.un~
2-
*.swo
3-
*.swp
4-
*.crx
5-
*.sublime*
6-
options/*.js
7-
node_modules/*
8-
dist
9-
jscoverage.json
10-
tags
11-
.cake_task_cache
1+
dist

background_scripts/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,11 @@ const sendRequestHandlers = {
584584
});
585585
},
586586

587+
launchSearchQuery({ query, openInNewTab }) {
588+
const disposition = openInNewTab ? "NEW_TAB" : "CURRENT_TAB";
589+
chrome.search.query({ disposition, text: query });
590+
},
591+
587592
domReady(_, sender) {
588593
const isTopFrame = sender.frameId == 0;
589594
if (!isTopFrame) return;

content_scripts/link_hints.js

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class LinkHintsMode {
361361
// We need documentElement to be ready in order to append links.
362362
if (!document.documentElement) return;
363363

364-
this.hintMarkerContainingDiv = null;
364+
this.containerEl = null;
365365
// Function that does the appropriate action on the selected link.
366366
this.linkActivator = undefined;
367367
// The link-hints "mode" (in the key-handler, indicator sense).
@@ -379,7 +379,7 @@ class LinkHintsMode {
379379
this.stableSortCount = 0;
380380
this.hintMarkers = hintDescriptors.map((desc) => this.createMarkerFor(desc));
381381
this.markerMatcher = Settings.get("filterLinkHints") ? new FilterHints() : new AlphabetHints();
382-
this.markerMatcher.fillInMarkers(this.hintMarkers, this.getNextZIndex.bind(this));
382+
this.markerMatcher.fillInMarkers(this.hintMarkers);
383383

384384
this.hintMode = new Mode();
385385
this.hintMode.init({
@@ -402,20 +402,33 @@ class LinkHintsMode {
402402
}
403403
});
404404

405+
this.renderHints();
406+
this.setIndicator();
407+
}
408+
409+
renderHints() {
410+
if (this.containerEl == null) {
411+
const div = DomUtils.createElement("div");
412+
div.id = "vimiumHintMarkerContainer";
413+
div.className = "vimiumReset";
414+
this.containerEl = div;
415+
document.documentElement.appendChild(div);
416+
}
417+
405418
// Append these markers as top level children instead of as child nodes to the link itself,
406419
// because some clickable elements cannot contain children, e.g. submit buttons.
407-
this.hintMarkerContainingDiv = DomUtils.addElementsToPage(
408-
this.hintMarkers.filter((m) => m.isLocalMarker()).map((m) => m.element),
409-
{ id: "vimiumHintMarkerContainer", className: "vimiumReset" },
410-
);
420+
const markerEls = this.hintMarkers.filter((m) => m.isLocalMarker()).map((m) => m.element);
421+
for (const el of markerEls) {
422+
this.containerEl.appendChild(el);
423+
}
411424

412425
// TODO(philc): 2024-03-27 Remove this hasPopoverSupport check once Firefox has popover support.
413426
// Also move this CSS into vimium.css.
414-
const hasPopoverSupport = this.hintMarkerContainingDiv.showPopover != null;
427+
const hasPopoverSupport = this.containerEl.showPopover != null;
415428
if (hasPopoverSupport) {
416-
this.hintMarkerContainingDiv.popover = "manual";
417-
this.hintMarkerContainingDiv.showPopover();
418-
Object.assign(this.hintMarkerContainingDiv.style, {
429+
this.containerEl.popover = "manual";
430+
this.containerEl.showPopover();
431+
Object.assign(this.containerEl.style, {
419432
top: 0,
420433
left: 0,
421434
position: "absolute",
@@ -431,16 +444,6 @@ class LinkHintsMode {
431444
this.setIndicator();
432445
}
433446

434-
// Increments and returns the Z index that should be used for the next hint marker on the page.
435-
getNextZIndex() {
436-
if (this.currentZIndex == null) {
437-
// This is the starting z-index value; it produces z-index values which are greater than all
438-
// of the other z-index values used by Vimium.
439-
this.currentZIndex = 2140000000;
440-
}
441-
return ++this.currentZIndex;
442-
}
443-
444447
setOpenLinkMode(mode, shouldPropagateToOtherFrames) {
445448
this.mode = mode;
446449
if (shouldPropagateToOtherFrames == null) {
@@ -476,7 +479,6 @@ class LinkHintsMode {
476479
el.style.left = localHint.rect.left + "px";
477480
el.style.top = localHint.rect.top + "px";
478481
// Each hint marker is assigned a different z-index.
479-
el.style.zIndex = this.getNextZIndex();
480482
el.className = "vimiumReset internalVimiumHintMarker vimiumHintMarker";
481483
Object.assign(marker, {
482484
element: el,
@@ -589,7 +591,6 @@ class LinkHintsMode {
589591
const { linksMatched, userMightOverType } = this.markerMatcher.getMatchingHints(
590592
this.hintMarkers,
591593
tabCount,
592-
this.getNextZIndex.bind(this),
593594
);
594595
if (linksMatched.length === 0) {
595596
this.deactivateMode();
@@ -622,7 +623,6 @@ class LinkHintsMode {
622623
const localHintMarkers = this.hintMarkers.filter((m) =>
623624
m.isLocalMarker() && (m.element.style.display !== "none")
624625
);
625-
626626
// Fill in the markers' rects, if necessary.
627627
for (const marker of localHintMarkers) {
628628
if (marker.markerRect == null) {
@@ -659,17 +659,16 @@ class LinkHintsMode {
659659
}
660660
}
661661

662-
// Rotate the z-indexes within each stack.
663-
for (const stack of stacks) {
662+
const newMarkers = []
663+
for (let stack of stacks) {
664664
if (stack.length > 1) {
665-
const zIndexes = stack.map((marker) => marker.element.style.zIndex);
666-
zIndexes.push(zIndexes[0]);
667-
for (let index = 0; index < stack.length; index++) {
668-
const marker = stack[index];
669-
marker.element.style.zIndex = zIndexes[index + 1];
670-
}
665+
// Push the last element to the beginning.
666+
stack = stack.splice(-1, 1).concat(stack)
671667
}
668+
newMarkers.push(...stack)
672669
}
670+
this.hintMarkers = newMarkers;
671+
this.renderHints();
673672
}
674673

675674
// When only one hint remains, activate it in the appropriate way. The current frame may or may
@@ -771,10 +770,10 @@ class LinkHintsMode {
771770
}
772771

773772
removeHintMarkers() {
774-
if (this.hintMarkerContainingDiv) {
775-
DomUtils.removeElement(this.hintMarkerContainingDiv);
773+
if (this.containerEl) {
774+
DomUtils.removeElement(this.containerEl);
776775
}
777-
this.hintMarkerContainingDiv = null;
776+
this.containerEl = null;
778777
}
779778
}
780779

@@ -877,7 +876,7 @@ class FilterHints {
877876
marker.element.innerHTML = spanWrap(caption);
878877
}
879878

880-
fillInMarkers(hintMarkers, getNextZIndex) {
879+
fillInMarkers(hintMarkers) {
881880
for (const marker of hintMarkers) {
882881
if (marker.isLocalMarker()) {
883882
this.renderMarker(marker);
@@ -886,10 +885,10 @@ class FilterHints {
886885

887886
// We use getMatchingHints() here (although we know that all of the hints will match) to get an
888887
// order on the hints and highlight the first one.
889-
return this.getMatchingHints(hintMarkers, 0, getNextZIndex);
888+
return this.getMatchingHints(hintMarkers, 0);
890889
}
891890

892-
getMatchingHints(hintMarkers, tabCount, getNextZIndex) {
891+
getMatchingHints(hintMarkers, tabCount) {
893892
// At this point, linkTextKeystrokeQueue and hintKeystrokeQueue have been updated to reflect the
894893
// latest input. Use them to filter the link hints accordingly.
895894
const matchString = this.hintKeystrokeQueue.join("");
@@ -910,7 +909,6 @@ class FilterHints {
910909

911910
if (this.activeHintMarker?.element) {
912911
this.activeHintMarker.element.classList.add("vimiumActiveHintMarker");
913-
this.activeHintMarker.element.style.zIndex = getNextZIndex();
914912
}
915913

916914
return {
@@ -927,7 +925,7 @@ class FilterHints {
927925
(keyChar.toLowerCase() !== keyChar) &&
928926
(this.linkHintNumbers.toLowerCase() !== this.linkHintNumbers.toUpperCase())
929927
) {
930-
// The the keyChar is upper case and the link hint "numbers" contain characters (e.g.
928+
// The keyChar is upper case and the link hint "numbers" contain characters (e.g.
931929
// [a-zA-Z]). We don't want some upper-case letters matching hints (above) and some matching
932930
// text (below), so we ignore such keys.
933931
return;

content_scripts/mode_normal.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,14 @@ class FocusSelector extends Mode {
509509
},
510510
});
511511

512-
this.hintContainingDiv = DomUtils.addElementsToPage(hints, {
513-
id: "vimiumInputMarkerContainer",
514-
className: "vimiumReset",
515-
});
512+
const div = DomUtils.createElement("div");
513+
div.id = "vimiumInputMarkerContainer";
514+
div.className = "vimiumReset";
515+
for (const el of hints) {
516+
div.appendChild(el);
517+
}
518+
this.hintContainerEl = div;
519+
document.documentElement.appendChild(div);
516520

517521
DomUtils.simulateSelect(visibleInputs[selectedInputIndex].element);
518522
if (visibleInputs.length === 1) {
@@ -525,7 +529,7 @@ class FocusSelector extends Mode {
525529

526530
exit() {
527531
super.exit();
528-
DomUtils.removeElement(this.hintContainingDiv);
532+
DomUtils.removeElement(this.hintContainerEl);
529533
if (document.activeElement && DomUtils.isEditable(document.activeElement)) {
530534
return new InsertMode({
531535
singleton: "post-find-mode/focus-input",

content_scripts/vimium.css

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
* don't use the same CSS class names that the page is using, so the page's CSS doesn't mess with
44
* the style of our Vimium dialogs.
55
*
6-
* The z-indexes of Vimium elements are very large, because we always want them to show on top. We
7-
* know that Chrome supports z-index values up to about 2^31. The values we use are large numbers
8-
* approaching that bound. However, we must leave headroom for link hints. Hint marker z-indexes
9-
* start at 2140000001.
6+
* We use the maximum z-index value for all Vimium elements to guarantee that they always appear on
7+
* top. Chrome supports z-index values up to 2,147,483,647 (= 2^31 - 1). We utilize the maximum
8+
* z-index value allowable to ensure Vimium elements have precedence over all other page elements.
109
*/
1110

1211
/*
@@ -60,7 +59,7 @@ tr.vimiumReset {
6059
vertical-align: baseline;
6160
white-space: normal;
6261
width: auto;
63-
z-index: 2140000000; /* Vimium's reference z-index value. */
62+
z-index: 2147483647;
6463
}
6564

6665
thead.vimiumReset, tbody.vimiumReset {
@@ -90,6 +89,7 @@ div.internalVimiumHintMarker {
9089
border: solid 1px #C38A22;
9190
border-radius: 3px;
9291
box-shadow: 0px 3px 7px 0px rgba(0, 0, 0, 0.3);
92+
z-index: 2147483647;
9393
}
9494

9595
div.internalVimiumHintMarker span {
@@ -153,7 +153,7 @@ iframe.vimiumHelpDialogFrame {
153153
display: block;
154154
position: fixed;
155155
border: none;
156-
z-index: 2139999997; /* Three less than the reference value. */
156+
z-index: 2147483647;
157157
}
158158

159159
div#vimiumHelpDialogContainer {
@@ -320,7 +320,7 @@ div.vimiumHUD {
320320
border-radius: 4px;
321321
box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.8);
322322
border: 1px solid #aaa;
323-
z-index: 2139999999;
323+
z-index: 2147483647;
324324
}
325325

326326
iframe.vimiumHUDFrame {
@@ -336,7 +336,7 @@ iframe.vimiumHUDFrame {
336336
right: 20px;
337337
margin: 0 0 0 -40%;
338338
border: none;
339-
z-index: 2139999998; /* Two less than the reference value. */
339+
z-index: 2147483647;
340340
opacity: 0;
341341
}
342342

@@ -413,15 +413,15 @@ iframe.vomnibarFrame {
413413
margin: 0 0 0 -40%;
414414
border: none;
415415
font-family: sans-serif;
416-
z-index: 2139999998; /* Two less than the reference value. */
416+
z-index: 2147483647;
417417
}
418418

419419
div.vimiumFlash {
420420
box-shadow: 0px 0px 4px 2px #4183C4;
421421
padding: 1px;
422422
background-color: transparent;
423423
position: absolute;
424-
z-index: 2140000000;
424+
z-index: 2147483647;
425425
}
426426

427427
/* UIComponent CSS */

lib/dom_utils.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,6 @@ const DomUtils = {
7979
}
8080
},
8181

82-
//
83-
// Adds a list of elements to a new container div, and adds that to the page.
84-
// Returns the container div.
85-
//
86-
// Note that adding these nodes all at once (via a parent div) is significantly faster than
87-
// one-by-one.
88-
addElementsToPage(elements, containerOptions) {
89-
const parent = this.createElement("div");
90-
if (containerOptions.id != null) parent.id = containerOptions.id;
91-
if (containerOptions.className != null) parent.className = containerOptions.className;
92-
for (const el of elements) parent.appendChild(el);
93-
document.documentElement.appendChild(parent);
94-
return parent;
95-
},
96-
9782
//
9883
// Remove an element from its DOM tree.
9984
//

lib/url_utils.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ const UrlUtils = {
8585
return false;
8686
},
8787

88-
// Converts :string into a Google search if it's not already a URL. We don't bother with escaping
89-
// characters as Chrome will do that for us.
88+
// Converts string into a full URL if it's not already one. We don't escape characters as the
89+
// browser will do that for us.
9090
async convertToUrl(string) {
9191
string = string.trim();
9292

@@ -98,7 +98,9 @@ const UrlUtils = {
9898
} else if (await this.isUrl(string)) {
9999
return this.createFullUrl(string);
100100
} else {
101-
return this.createSearchUrl(string);
101+
const message = `convertToUrl: can't convert "${string}" into a URL. This shouldn't happen.`;
102+
console.error(message);
103+
return null;
102104
}
103105
},
104106

@@ -125,13 +127,8 @@ const UrlUtils = {
125127
}
126128
},
127129

128-
// Create a search URL from the given :query (using either the provided search URL, or the default
129-
// one). It would be better to pull the default search engine from Chrome itself. However, Chrome
130-
// does not provide an API for doing so.
130+
// Create a search URL from the given :query using the provided search URL.
131131
createSearchUrl(query, searchUrl) {
132-
if (searchUrl == null) {
133-
searchUrl = Settings.get("searchUrl") || Settings.defaultOptions.defaultSearchUrl;
134-
}
135132
if (!["%s", "%S"].some((token) => searchUrl.indexOf(token) >= 0)) {
136133
searchUrl += "%s";
137134
}
@@ -142,7 +139,9 @@ const UrlUtils = {
142139
// Map a search query to its URL encoded form. The query may be either a string or an array of
143140
// strings. E.g. "BBC Sport" -> "BBC%20Sport".
144141
createSearchQuery(query) {
145-
if (typeof query === "string") query = query.split(/\s+/);
142+
if (typeof query === "string") {
143+
query = query.split(/\s+/);
144+
}
146145
return query.map(encodeURIComponent).join("%20");
147146
},
148147
};

manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
// loads. This permission was required when moving to manifest V3.
3131
"scripting",
3232
"favicon", // The favicon permission is not yet supported by Firefox.
33-
"webNavigation"
33+
"webNavigation",
34+
"search"
3435
],
3536
"content_scripts": [
3637
{

pages/completion_engines.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</p>
4747
<header>Available Completion Engines</header>
4848
<p>
49-
Search completion is available in this version of Vimium for the the following custom search engines.
49+
Search completion is available in this version of Vimium for the following custom search engines.
5050
</p>
5151
<p>
5252
<dl id="engineList"></dl>

0 commit comments

Comments
 (0)