Skip to content
Open
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
6 changes: 3 additions & 3 deletions background_scripts/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ class TabCompleter {
const suggestion = new Suggestion({
queryTerms,
description: "tab",
url: tab.url,
title: tab.title,
url: tab.url || "",
title: tab.title || "",
tabId: tab.id,
deDuplicate: false,
});
Expand Down Expand Up @@ -693,7 +693,7 @@ const RankingUtils = {
let matchedTerm = false;
for (const thing of things) {
if (!matchedTerm) {
matchedTerm = thing.match(regexp);
matchedTerm = thing?.match(regexp);
Copy link
Owner

@philc philc Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This null-check seems redundant if we're populating the url and title with empty strings above, right?

Of the two checks you have, I think I would prefer keeping only the second: allow these fields to be null, document why they can be null, and update the matching code to handle null fields.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were other places in the code like https://github.com/philc/vimium/blob/master/background_scripts/completion.js#L417 that suggest there is a built-in assumption that the url field is never null:

    const result = new Suggestion({
      queryTerms,
      description: "domain",
      // This should be the URL or the domain, or an empty string, but not null.
      url: domainsAndScores[0]?.[0] || "",
      relevancy: 2.0,
    });

In https://github.com/philc/vimium/blob/master/background_scripts/completion.js#L484 we're calling matches directly on tabs:

    const tabs = await chrome.tabs.query({});
    const results = tabs.filter((tab) => RankingUtils.matches(queryTerms, tab.url, tab.title));

That's why I had to do both changes.

}
}
if (!matchedTerm) return false;
Expand Down