Skip to content

Commit

Permalink
Support "top" or "end" for more cases to open child tabs (follow-up of
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 16, 2024
1 parent 6be7898 commit 4bbf936
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 6 deletions.
2 changes: 2 additions & 0 deletions webextensions/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"tabbar_newTabAction_independent_command": { "message": "Independent Tab" },
"tabbar_newTabAction_child_label": { "message": "&Child Tab" },
"tabbar_newTabAction_child_command": { "message": "Child Tab" },
"tabbar_newTabAction_childTop_command": { "message": "First Child Tab" },
"tabbar_newTabAction_childEnd_command": { "message": "Last Child Tab" },
"tabbar_newTabAction_sibling_label": { "message": "&Sibling Tab" },
"tabbar_newTabAction_sibling_command": { "message": "Sibling Tab" },
"tabbar_newTabAction_nextSibling_label": { "message": "&Next Sibling Tab" },
Expand Down
2 changes: 2 additions & 0 deletions webextensions/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"tabbar_newTabAction_independent_command": { "message": "独立したタブ" },
"tabbar_newTabAction_child_label": { "message": "子タブ(&C)" },
"tabbar_newTabAction_child_command": { "message": "子タブ" },
"tabbar_newTabAction_childTop_command": { "message": "最初の子タブ" },
"tabbar_newTabAction_childEnd_command": { "message": "最後の子タブ" },
"tabbar_newTabAction_sibling_label": { "message": "同階層のタブ(&S)" },
"tabbar_newTabAction_sibling_command": { "message": "同階層のタブ" },
"tabbar_newTabAction_nextSibling_label": { "message": "同階層の隣のタブ(&N)" },
Expand Down
11 changes: 9 additions & 2 deletions webextensions/background/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,16 @@ export async function openNewTabAs(options = {}) {
insertAfter = Tab.getLastTab(activeTab.windowId);
break;

case Constants.kNEWTAB_OPEN_AS_CHILD: {
case Constants.kNEWTAB_OPEN_AS_CHILD:
case Constants.kNEWTAB_OPEN_AS_CHILD_TOP:
case Constants.kNEWTAB_OPEN_AS_CHILD_END: {
parent = activeTab;
const refTabs = Tree.getReferenceTabsForNewChild(null, parent);
const insertAt = options.as == Constants.kNEWTAB_OPEN_AS_CHILD_TOP ?
Constants.kINSERT_TOP :
options.as == Constants.kNEWTAB_OPEN_AS_CHILD_END ?
Constants.kINSERT_END :
undefined;
const refTabs = Tree.getReferenceTabsForNewChild(null, parent, { insertAt });
insertBefore = refTabs.insertBefore;
insertAfter = refTabs.insertAfter;
log('detected reference tabs: ',
Expand Down
24 changes: 23 additions & 1 deletion webextensions/background/handle-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ async function onShortcutCommand(command) {
as: Constants.kNEWTAB_OPEN_AS_CHILD
});
return;
case 'newChildTabTop':
Commands.openNewTabAs({
baseTab: activeTab,
as: Constants.kNEWTAB_OPEN_AS_CHILD_TOP
});
return;
case 'newChildTabEnd':
Commands.openNewTabAs({
baseTab: activeTab,
as: Constants.kNEWTAB_OPEN_AS_CHILD_END
});
return;
case 'newSiblingTab':
Commands.openNewTabAs({
baseTab: activeTab,
Expand Down Expand Up @@ -637,7 +649,17 @@ function onMessageExternal(message, sender) {
let behavior = configs.autoAttachOnDuplicated;
switch (String(message.as || 'sibling').toLowerCase()) {
case 'child':
behavior = Constants.kNEWTAB_OPEN_AS_CHILD;
behavior = behavior == Constants.kNEWTAB_OPEN_AS_CHILD_TOP ?
Constants.kNEWTAB_OPEN_AS_CHILD_TOP :
behavior == Constants.kNEWTAB_OPEN_AS_CHILD_END ?
Constants.kNEWTAB_OPEN_AS_CHILD_END :
Constants.kNEWTAB_OPEN_AS_CHILD;
break;
case 'first-child':
behavior = Constants.kNEWTAB_OPEN_AS_CHILD_TOP;
break;
case 'last-child':
behavior = Constants.kNEWTAB_OPEN_AS_CHILD_END;
break;
case 'sibling':
behavior = Constants.kNEWTAB_OPEN_AS_SIBLING;
Expand Down
2 changes: 1 addition & 1 deletion webextensions/background/handle-new-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ Tab.onUpdated.addListener((tab, changeInfo) => {
handleNewTabFromActiveTab(tab, {
url: tab.url,
activeTab: possibleOpenerTab,
autoAttachBehavior: Constants.kNEWTAB_OPEN_AS_CHILD,
autoAttachBehavior: configs.autoAttachOnOpenedWithOwner,
context: TSTAPI.kNEWTAB_CONTEXT_FROM_ABOUT_ADDONS,
});
return;
Expand Down
4 changes: 3 additions & 1 deletion webextensions/background/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,9 @@ export async function behaveAutoAttachedTabs(tabs, options = {}) {
}
return false;

case Constants.kNEWTAB_OPEN_AS_CHILD: {
case Constants.kNEWTAB_OPEN_AS_CHILD:
case Constants.kNEWTAB_OPEN_AS_CHILD_TOP:
case Constants.kNEWTAB_OPEN_AS_CHILD_END: {
if (options.baseTabs && !options.baseTab)
options.baseTab = options.baseTabs[0];
let moved = false;
Expand Down
6 changes: 6 additions & 0 deletions webextensions/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
"newChildTab": {
"description": "__MSG_tabbar_newTabButton_tooltip__: __MSG_tabbar_newTabAction_child_command__"
},
"newChildTabTop": {
"description": "__MSG_tabbar_newTabButton_tooltip__: __MSG_tabbar_newTabAction_childTop_command__"
},
"newChildTabEnd": {
"description": "__MSG_tabbar_newTabButton_tooltip__: __MSG_tabbar_newTabAction_childEnd_command__"
},
"newSiblingTab": {
"description": "__MSG_tabbar_newTabButton_tooltip__: __MSG_tabbar_newTabAction_sibling_command__"
},
Expand Down
12 changes: 11 additions & 1 deletion webextensions/sidebar/mouse-event-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,17 @@ function onNewTabActionSelect(item, event) {
action = Constants.kNEWTAB_OPEN_AS_ORPHAN;
break;
case 'child':
action = Constants.kNEWTAB_OPEN_AS_CHILD;
const hints = new Set([
configs.autoAttachOnNewTabCommand,
configs.autoAttachOnNewTabButtonMiddleClick,
configs.autoAttachOnNewTabButtonAccelClick,
]);
if (hints.has(Constants.kNEWTAB_OPEN_AS_CHILD_TOP))
action = Constants.kNEWTAB_OPEN_AS_CHILD_TOP;
else if (hints.has(Constants.kNEWTAB_OPEN_AS_CHILD_END))
action = Constants.kNEWTAB_OPEN_AS_CHILD_END;
else
action = Constants.kNEWTAB_OPEN_AS_CHILD;
break;
case 'sibling':
action = Constants.kNEWTAB_OPEN_AS_SIBLING;
Expand Down

0 comments on commit 4bbf936

Please sign in to comment.