Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions locales/en-US/browser/browser/preferences/zen-preferences.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ zen-workspace-shortcut-switch-10 = Switch to Workspace 10
zen-workspace-shortcut-forward = Forward Workspace
zen-workspace-shortcut-backward = Backward Workspace
zen-workspace-shortcut-create = Create New Workspace
zen-move-tab-shortcut-workspace-1 = Move Tab to Workspace 1
zen-move-tab-shortcut-workspace-2 = Move Tab to Workspace 2
zen-move-tab-shortcut-workspace-3 = Move Tab to Workspace 3
zen-move-tab-shortcut-workspace-4 = Move Tab to Workspace 4
zen-move-tab-shortcut-workspace-5 = Move Tab to Workspace 5
zen-move-tab-shortcut-workspace-6 = Move Tab to Workspace 6
zen-move-tab-shortcut-workspace-7 = Move Tab to Workspace 7
zen-move-tab-shortcut-workspace-8 = Move Tab to Workspace 8
zen-move-tab-shortcut-workspace-9 = Move Tab to Workspace 9
zen-move-tab-shortcut-workspace-10 = Move Tab to Workspace 10
zen-move-tab-shortcut-forward = Move Tab Forward
zen-move-tab-shortcut-backward = Move Tab Backward
zen-sidebar-shortcut-toggle = Toggle Sidebar's Width
zen-pinned-tab-shortcut-reset = Reset Pinned Tab to Pinned URL
zen-split-view-shortcut-grid = Toggle Split View Grid
Expand Down
3 changes: 3 additions & 0 deletions locales/en-US/browser/browser/zen-workspaces.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ zen-workspaces-close-all-unpinned-tabs-title =
.label = Clear
.tooltiptext = Close all unpinned tabs

zen-workspaces-moved-tab-toast = Moved tab to <span>{ $name }</span>
zen-workspaces-moved-tabs-toast = Moved { $count } tabs to <span>{ $name }</span>

zen-panel-ui-workspaces-change-forward =
.label = Next Space

Expand Down
13 changes: 13 additions & 0 deletions src/browser/base/content/zen-commands.inc.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
<command id="cmd_zenWorkspaceSwitch9" />
<command id="cmd_zenWorkspaceSwitch10" />

<command id="cmd_zenMoveTabToWorkspace1" />
<command id="cmd_zenMoveTabToWorkspace2" />
<command id="cmd_zenMoveTabToWorkspace3" />
<command id="cmd_zenMoveTabToWorkspace4" />
<command id="cmd_zenMoveTabToWorkspace5" />
<command id="cmd_zenMoveTabToWorkspace6" />
<command id="cmd_zenMoveTabToWorkspace7" />
<command id="cmd_zenMoveTabToWorkspace8" />
<command id="cmd_zenMoveTabToWorkspace9" />
<command id="cmd_zenMoveTabToWorkspace10" />
<command id="cmd_zenMoveTabForward" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Between spaces right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Exactly. Missed putting it into the name

<command id="cmd_zenMoveTabBackward" />

<command id="cmd_zenOpenZenThemePicker" />
<command id="cmd_zenChangeWorkspaceTab" />
<command id="cmd_zenToggleTabsOnRight" />
Expand Down
18 changes: 17 additions & 1 deletion src/zen/common/zen-sets.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ document.addEventListener(
case "cmd_zenWorkspaceBackward":
gZenWorkspaces.changeWorkspaceShortcut(-1);
break;
case "cmd_zenMoveTabForward":
gZenWorkspaces.moveActiveTabShortcut(1);
break;
case "cmd_zenMoveTabBackward":
gZenWorkspaces.moveActiveTabShortcut(-1);
break;
case "cmd_zenSplitViewGrid":
gZenViewSplitter.toggleShortcut("grid");
break;
Expand Down Expand Up @@ -152,14 +158,24 @@ document.addEventListener(
break;
}
default:
gZenGlanceManager.handleMainCommandSet(event);
if (event.target.id.startsWith("cmd_zenWorkspaceSwitch")) {
const index =
parseInt(
event.target.id.replace("cmd_zenWorkspaceSwitch", ""),
10
) - 1;
gZenWorkspaces.shortcutSwitchTo(index);
} else if (
event.target.id.startsWith("cmd_zenMoveTabToWorkspace")
) {
const index =
parseInt(
event.target.id.replace("cmd_zenMoveTabToWorkspace", ""),
10
) - 1;
gZenWorkspaces.shortcutMoveTabTo(index);
} else {
gZenGlanceManager.handleMainCommandSet(event);
}
break;
}
Expand Down
54 changes: 53 additions & 1 deletion src/zen/kbs/ZenKeyboardShortcuts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,50 @@ class KeyShortcut {
}
}

function createMoveTabShortcuts() {
const shortcuts = [];
for (let i = 10; i > 0; i--) {
shortcuts.push(
new KeyShortcut(
`zen-move-tab-to-workspace-${i}`,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To be honest, I dont think we should have shortcuts to move these to individual spaces, they would clutter up the keyboard shortcuts too much.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I see your point. My original pain point was that most of the time I use shortcuts for switching between workspaces, and switching between tabs within a workspace (ctrl + [1-9], cmd + [1-9] respectively, on Mac). So when I clicked a link, and it opened the tab in a "wrong" workspace, I'd want to move it to the "correct" one. Since there is already a built-in "Move tab" option, when you right click the tab itself, I thought making a keybind for it would make sense. I also read the issues linked in the description, although those went kind of stale.
If you know any existing way to address my pain point, or propose alternatives, I'm open to collaborate.

AppConstants.platform == "macosx" ? `${i === 10 ? 0 : i}` : "",
"",
ZEN_WORKSPACE_SHORTCUTS_GROUP,
nsKeyShortcutModifiers.fromObject(
AppConstants.platform == "macosx"
? { ctrl: true, shift: true }
: {}
),
`cmd_zenMoveTabToWorkspace${i}`,
`zen-move-tab-shortcut-workspace-${i}`
)
);
}
shortcuts.push(
new KeyShortcut(
"zen-move-tab-forward",
"",
"",
ZEN_WORKSPACE_SHORTCUTS_GROUP,
nsKeyShortcutModifiers.fromObject({}),
"cmd_zenMoveTabForward",
"zen-move-tab-shortcut-forward"
)
);
shortcuts.push(
new KeyShortcut(
"zen-move-tab-backward",
"",
"",
ZEN_WORKSPACE_SHORTCUTS_GROUP,
nsKeyShortcutModifiers.fromObject({}),
"cmd_zenMoveTabBackward",
"zen-move-tab-shortcut-backward"
)
);
return shortcuts;
}

class nsZenKeyboardShortcutsLoader {
constructor() {}

Expand Down Expand Up @@ -749,6 +793,8 @@ class nsZenKeyboardShortcutsLoader {
)
);

newShortcutList.push(...createMoveTabShortcuts());

// Split view
newShortcutList.push(
new KeyShortcut(
Expand Down Expand Up @@ -832,7 +878,7 @@ class nsZenKeyboardShortcutsLoader {
}

class nsZenKeyboardShortcutsVersioner {
static LATEST_KBS_VERSION = 18;
static LATEST_KBS_VERSION = 19;

constructor() {}

Expand Down Expand Up @@ -1228,6 +1274,12 @@ class nsZenKeyboardShortcutsVersioner {
);
}

if (version < 19) {
// Migrate from version 18 to 19.
// Add shortcuts to move tab(s) to workspace 1-10 and forward/backward
data.push(...createMoveTabShortcuts());
}

return data;
}
}
Expand Down
66 changes: 66 additions & 0 deletions src/zen/spaces/ZenSpaceManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,72 @@ class nsZenWorkspaces {
await this.changeWorkspace(workspaceToSwitch);
}

async moveActiveTabShortcut(offset = 1) {
const workspaces = this.getWorkspaces();
const activeWorkspace = this.getActiveWorkspace();
const workspaceIndex = workspaces.indexOf(activeWorkspace);
let targetIndex = workspaceIndex + offset;
if (this.shouldWrapAroundNavigation) {
targetIndex = (targetIndex + workspaces.length) % workspaces.length;
} else {
targetIndex = Math.max(0, Math.min(workspaces.length - 1, targetIndex));
}
if (targetIndex === workspaceIndex) {
return;
}
await this.shortcutMoveTabTo(targetIndex);
}

async shortcutMoveTabTo(index) {
const workspaces = this.getWorkspaces();
if (index >= workspaces.length || index < 0) {
return;
}
const targetWorkspace = workspaces[index];
const targetId = targetWorkspace.uuid;
if (targetId === this.activeWorkspace) {
return;
}
const sourceId = this.activeWorkspace;
const allSelected = gBrowser.selectedTab.multiselected
? gBrowser.selectedTabs
: [gBrowser.selectedTab];
const tabs = allSelected.filter(t => !t.hasAttribute("zen-empty-tab"));
if (!tabs.length) {
return;
}
const movedTabs = new Set(tabs);

for (const tab of tabs) {
if (this.lastSelectedWorkspaceTabs[sourceId] === tab) {
delete this.lastSelectedWorkspaceTabs[sourceId];
}
this.moveTabToWorkspace(tab, targetId);
}

if (movedTabs.has(gBrowser.selectedTab)) {
const remaining = gBrowser.visibleTabs.find(
t => !movedTabs.has(t) && !t.pinned && !t.closing
);
if (remaining) {
gBrowser.selectedTab = remaining;
} else {
this.selectEmptyTab();
}
}

const tabCount = tabs.length;
const messageId = tabCount === 1
? "zen-workspaces-moved-tab-toast"
: "zen-workspaces-moved-tabs-toast";
gZenUIManager.showToast(messageId, {
l10nArgs: {
name: targetWorkspace.name,
count: tabCount,
},
});
}

isBookmarkInAnotherWorkspace(bookmark) {
if (!this._workspaceBookmarksCache?.bookmarks) {
return false;
Expand Down
2 changes: 2 additions & 0 deletions src/zen/tests/spaces/browser.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ support-files = [

["browser_unload_all_other_spaces.js"]

["browser_move_tab_to_workspace.js"]

["browser_workspace_bookmarks.js"]
Loading