Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature move current tab to an existing window #3925

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add vim bar suggestion for window
dyckia committed Sep 28, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 0b8cb43492f81d09b8553de51e8e5cee7d158364
3 changes: 3 additions & 0 deletions background_scripts/commands.js
Original file line number Diff line number Diff line change
@@ -225,6 +225,7 @@ const Commands = {
"Vomnibar.activateBookmarks",
"Vomnibar.activateBookmarksInNewTab",
"Vomnibar.activateTabSelection",
"Vomnibar.moveTabToWindow",
"Vomnibar.activateEditUrl",
"Vomnibar.activateEditUrlInNewTab"],
findCommands: ["enterFindMode", "performFind", "performBackwardsFind"],
@@ -334,6 +335,7 @@ const defaultKeyMappings = {
"o": "Vomnibar.activate",
"O": "Vomnibar.activateInNewTab",
"T": "Vomnibar.activateTabSelection",
"w": "Vomnibar.moveTabToWindow",
"b": "Vomnibar.activateBookmarks",
"B": "Vomnibar.activateBookmarksInNewTab",
"ge": "Vomnibar.activateEditUrl",
@@ -459,6 +461,7 @@ const commandDescriptions = {
"Vomnibar.activate": ["Open URL, bookmark or history entry", { topFrame: true }],
"Vomnibar.activateInNewTab": ["Open URL, bookmark or history entry in a new tab", { topFrame: true }],
"Vomnibar.activateTabSelection": ["Search through your open tabs", { topFrame: true }],
"Vomnibar.moveTabToWindow": ["Move current tab to an existing window", { topFrame: true }],
"Vomnibar.activateBookmarks": ["Open a bookmark", { topFrame: true }],
"Vomnibar.activateBookmarksInNewTab": ["Open a bookmark in a new tab", { topFrame: true }],
"Vomnibar.activateEditUrl": ["Edit the current URL", { topFrame: true }],
62 changes: 62 additions & 0 deletions background_scripts/completion.js
Original file line number Diff line number Diff line change
@@ -490,6 +490,67 @@ class TabCompleter {
}
}

// Searches through all windows, matching on title and URL.
class WindowCompleter {
filter({ name, queryTerms }, onComplete) {
if ((name !== "windows") && (queryTerms.length === 0))
return onComplete([]);

// chrome.tabs.query({}, tabs => {
// const results = tabs.filter(tab => RankingUtils.matches(queryTerms, tab.url, tab.title));
// const suggestions = results.map(tab => {
// const suggestion = new Suggestion({
// queryTerms,
// type: "tab",
// url: tab.url,
// title: tab.title,
// tabId: tab.id,
// deDuplicate: false
// });
// suggestion.relevancy = this.computeRelevancy(suggestion);
// return suggestion;
// }).sort((a, b) => b.relevancy - a.relevancy);

chrome.windows.getAll({populate: true}, windows => {
const curTabId = chrome.tabs.getCurrent(tab => tab.id);
const results = windows.filter(window => RankingUtils.matches(queryTerms, window.tabs[0].url, window.tabs[0].title));
const suggestions = results.map(window => {
const suggestion = new Suggestion({
queryTerms,
type: "window",
url: window.tabs[0].url,
title: window.tabs[0].title,
tabId: curTabId,
windowId: window.id,
deDuplicate: false,
});
suggestion.relevancy = this.computeRelevancy(suggestion);
return suggestion;
}).sort((a, b) => b.relevancy - a.relevancy);
// Boost relevancy with a multiplier so a relevant tab doesn't
// get crowded out by results from competing completers. To
// prevent tabs from crowding out everything else in turn,
// penalize them for being further down the results list by
// scaling on a hyperbola starting at 1 and approaching 0
// asymptotically for higher indexes. The multiplier and the
// curve fall-off were objectively chosen on the grounds that
// they seem to work pretty well.
suggestions.forEach(function(suggestion,i) {
suggestion.relevancy *= 8;
return suggestion.relevancy /= ( (i / 4) + 1 );
});
onComplete(suggestions);
});
}

computeRelevancy(suggestion) {
if (suggestion.queryTerms.length)
return RankingUtils.wordRelevancy(suggestion.queryTerms, suggestion.url, suggestion.title);
else
return BgUtils.tabRecency.recencyScore(suggestion.tabId);
}
}

class SearchEngineCompleter {
constructor() {
this.previousSuggestions = null;
@@ -1091,6 +1152,7 @@ Object.assign(global, {
HistoryCompleter,
DomainCompleter,
TabCompleter,
WindowCompleter,
SearchEngineCompleter,
HistoryCache,
RankingUtils,
16 changes: 13 additions & 3 deletions background_scripts/main.js
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ const completionSources = {
history: new HistoryCompleter,
domains: new DomainCompleter,
tabs: new TabCompleter,
windows: new WindowCompleter,
searchEngines: new SearchEngineCompleter
};

@@ -52,10 +53,12 @@ const completers = {
completionSources.history,
completionSources.domains,
completionSources.tabs,
completionSources.searchEngines
]),
completionSources.windows,
completionSources.searchEngines,
]),
bookmarks: new MultiCompleter([completionSources.bookmarks]),
tabs: new MultiCompleter([completionSources.tabs])
tabs: new MultiCompleter([completionSources.tabs]),
windows: new MultiCompleter([completionSources.windows]),
};

const completionHandlers = {
@@ -225,6 +228,12 @@ const selectSpecificTab = request => chrome.tabs.get(request.id, function(tab) {
return chrome.tabs.update(request.id, { active: true });
});

const moveTabToSpecificWindow = request => chrome.tabs.move(request.tabId, {windowId: request.windowId, index: -1}, function(tab) {
if (chrome.windows != null)
chrome.windows.update(tab.windowId, { focused: true });
return chrome.tabs.update(request.tabId, { active: true });
});

const moveTab = function({count, tab, registryEntry}) {
if (registryEntry.command === "moveTabLeft")
count = -count;
@@ -641,6 +650,7 @@ var sendRequestHandlers = {
frameFocused: handleFrameFocused,
nextFrame: BackgroundCommands.nextFrame,
selectSpecificTab,
moveTabToSpecificWindow,
createMark: Marks.create.bind(Marks),
gotoMark: Marks.goto.bind(Marks),
// Send a message to all frames in the current tab.
1 change: 1 addition & 0 deletions content_scripts/mode_normal.js
Original file line number Diff line number Diff line change
@@ -274,6 +274,7 @@ if (typeof Vomnibar !== 'undefined') {
"Vomnibar.activate": Vomnibar.activate.bind(Vomnibar),
"Vomnibar.activateInNewTab": Vomnibar.activateInNewTab.bind(Vomnibar),
"Vomnibar.activateTabSelection": Vomnibar.activateTabSelection.bind(Vomnibar),
"Vomnibar.moveTabToWindow": Vomnibar.moveTabToWindow.bind(Vomnibar),
"Vomnibar.activateBookmarks": Vomnibar.activateBookmarks.bind(Vomnibar),
"Vomnibar.activateBookmarksInNewTab": Vomnibar.activateBookmarksInNewTab.bind(Vomnibar),
"Vomnibar.activateEditUrl": Vomnibar.activateEditUrl.bind(Vomnibar),
7 changes: 7 additions & 0 deletions content_scripts/vomnibar.js
Original file line number Diff line number Diff line change
@@ -31,6 +31,13 @@ const Vomnibar = {
});
},

moveTabToWindow(sourceFrameId) {
return this.open(sourceFrameId, {
completer: "windows",
selectFirst: true,
});
},

activateBookmarks(sourceFrameId) {
return this.open(sourceFrameId, {
completer: "bookmarks",
20 changes: 12 additions & 8 deletions pages/vomnibar.js
Original file line number Diff line number Diff line change
@@ -365,7 +365,8 @@ class BackgroundCompleter {
this.name = name;
this.completionActions = {
navigateToUrl(url) { return openInNewTab => Vomnibar.getCompleter().launchUrl(url, openInNewTab); },
switchToTab(tabId) { return () => chrome.runtime.sendMessage({handler: "selectSpecificTab", id: tabId}); }
switchToTab(tabId) { return () => chrome.runtime.sendMessage({handler: "selectSpecificTab", id: tabId}); },
moveToWindow(tabId, windowId) { return () => chrome.runtime.sendMessage({handler: "moveTabToSpecificWindow", tabId: tabId, windowId: windowId}); }
};

this.port = chrome.runtime.connect({name: "completions"});
@@ -381,14 +382,17 @@ class BackgroundCompleter {
if (msg.id === this.messageId) {
// The result objects coming from the background page will be of the form:
// { html: "", type: "", url: "", ... }
// Type will be one of [tab, bookmark, history, domain, search], or a custom search engine description.
// Type will be one of [tab, bookmark, history, domain, search, window], or a custom search engine description.
for (let result of msg.results) {
Object.assign(result, {
performAction:
result.type === "tab" ?
this.completionActions.switchToTab(result.tabId) :
this.completionActions.navigateToUrl(result.url)
});
let completionAction;
if (result.type === "tab") {
completionAction = this.completionActions.switchToTab(result.tabId);
} else if (result.type === "window") {
completionAction = this.completionActions.moveToWindow(result.tabId, 1);
} else {
completionAction = this.completionActions.navigateToUrl(result.url);
}
Object.assign(result, { performAction: completionAction });
}

// Handle the message, but only if it hasn't arrived too late.