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
Show file tree
Hide file tree
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 move tab function
  • Loading branch information
dyckia committed Sep 28, 2021
commit 29452b8d5c50f57017fb4c1557487dbf0bff0e7f
71 changes: 29 additions & 42 deletions background_scripts/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,58 +496,45 @@ class WindowCompleter {
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,
chrome.tabs.query({currentWindow: true, active : true}, tabs => {
const curTab = tabs[0];
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: curTab.id,
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 );
});
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);
});
onComplete(suggestions);
});
}

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

Expand Down
13 changes: 8 additions & 5 deletions background_scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ 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 moveTabToSpecificWindow = request => chrome.tabs.move(request.tabId, {windowId: request.windowId, index: -1});

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

const moveTab = function({count, tab, registryEntry}) {
if (registryEntry.command === "moveTabLeft")
Expand Down
2 changes: 1 addition & 1 deletion pages/vomnibar.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class BackgroundCompleter {
if (result.type === "tab") {
completionAction = this.completionActions.switchToTab(result.tabId);
} else if (result.type === "window") {
completionAction = this.completionActions.moveToWindow(result.tabId, 1);
completionAction = this.completionActions.moveToWindow(result.tabId, result.windowId);
} else {
completionAction = this.completionActions.navigateToUrl(result.url);
}
Expand Down