Skip to content

Commit e42950b

Browse files
committed
Add support for middle-clicking (and double-clicking) the document tab bar to create a new document (#3363)
1 parent f5ef1a9 commit e42950b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

frontend/src/components/window/workspace/Panel.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import type { Editor } from "@graphite/editor";
2020
import { type LayoutKeysGroup, type Key } from "@graphite/messages";
2121
import { platformIsMac, isEventSupported } from "@graphite/utility-functions/platform";
22-
2322
import { extractPixelData } from "@graphite/utility-functions/rasterization";
2423
2524
import LayoutCol from "@graphite/components/layout/LayoutCol.svelte";
@@ -30,6 +29,7 @@
3029
import TextLabel from "@graphite/components/widgets/labels/TextLabel.svelte";
3130
import UserInputLabel from "@graphite/components/widgets/labels/UserInputLabel.svelte";
3231
32+
const BUTTON_LEFT = 0;
3333
const BUTTON_MIDDLE = 1;
3434
3535
const editor = getContext<Editor>("editor");
@@ -41,6 +41,7 @@
4141
export let panelType: PanelType | undefined = undefined;
4242
export let clickAction: ((index: number) => void) | undefined = undefined;
4343
export let closeAction: ((index: number) => void) | undefined = undefined;
44+
export let emptySpaceAction: (() => void) | undefined = undefined;
4445
4546
let className = "";
4647
export { className as class };
@@ -93,6 +94,11 @@
9394
});
9495
}
9596
97+
function onEmptySpaceAction(e: MouseEvent) {
98+
if (e.target !== e.currentTarget) return;
99+
if (e.button === BUTTON_MIDDLE || (e.button === BUTTON_LEFT && e.detail === 2)) emptySpaceAction?.();
100+
}
101+
96102
export async function scrollTabIntoView(newIndex: number) {
97103
await tick();
98104
tabElements[newIndex]?.div?.()?.scrollIntoView();
@@ -101,7 +107,7 @@
101107

102108
<LayoutCol on:pointerdown={() => panelType && editor.handle.setActivePanel(panelType)} class={`panel ${className}`.trim()} {classes} style={styleName} {styles}>
103109
<LayoutRow class="tab-bar" classes={{ "min-widths": tabMinWidths }}>
104-
<LayoutRow class="tab-group" scrollableX={true}>
110+
<LayoutRow class="tab-group" scrollableX={true} on:click={onEmptySpaceAction} on:auxclick={onEmptySpaceAction}>
105111
{#each tabLabels as tabLabel, tabIndex}
106112
<LayoutRow
107113
class="tab"

frontend/src/components/window/workspace/Workspace.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
tabCloseButtons={true}
143143
tabMinWidths={true}
144144
tabLabels={documentTabLabels}
145+
emptySpaceAction={() => editor.handle.newDocumentDialog()}
145146
clickAction={(tabIndex) => editor.handle.selectDocument($portfolio.documents[tabIndex].id)}
146147
closeAction={(tabIndex) => editor.handle.closeDocumentWithConfirmation($portfolio.documents[tabIndex].id)}
147148
tabActiveIndex={$portfolio.activeDocumentIndex}

0 commit comments

Comments
 (0)