Skip to content

Commit 74d9c91

Browse files
committed
Fix ShortcutLabel drawing of consecutive key labels
1 parent 8ca546c commit 74d9c91

File tree

5 files changed

+50
-25
lines changed

5 files changed

+50
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ profile.json.gz
99
flamegraph.svg
1010
.idea/
1111
.direnv
12+
.DS_Store
1213
hierarchical_message_system_tree.txt
1314
hierarchical_message_system_tree.html

editor/src/messages/input_mapper/input_mappings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ pub fn input_mappings() -> Mapping {
411411
entry!(KeyDown(Equal); modifiers=[Accel], action_dispatch=NavigationMessage::CanvasZoomIncrease { center_on_mouse: false }),
412412
entry!(KeyDown(Minus); modifiers=[Accel], action_dispatch=NavigationMessage::CanvasZoomDecrease { center_on_mouse: false }),
413413
entry!(WheelScroll; modifiers=[Control], action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
414+
entry!(WheelScroll; modifiers=[Command], action_dispatch=NavigationMessage::CanvasZoomMouseWheel),
414415
entry!(WheelScroll; modifiers=[Shift], action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: true }),
415416
entry!(WheelScroll; action_dispatch=NavigationMessage::CanvasPanMouseWheel { use_y_as_x: false }),
416417
entry!(KeyDown(PageUp); modifiers=[Shift], action_dispatch=NavigationMessage::CanvasPanByViewportFraction { delta: DVec2::new(1., 0.) }),

frontend/src/components/widgets/labels/ShortcutLabel.svelte

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
1010
export let shortcut: ActionShortcut;
1111
12-
function keyTextOrIconList(keyGroup: LabeledShortcut): { label?: string; icon?: IconName; mouseMotion?: MouseMotion }[] {
13-
const list = keyGroup.map((labeledKeyOrMouseMotion) => {
12+
function keyTextOrIconList(keyGroup: LabeledShortcut): ({ label?: string; icon?: IconName }[] | { mouseMotion?: MouseMotion }[])[] {
13+
const list = keyGroup.map((labeledKeyOrMouseMotion): { label?: string; icon?: IconName; mouseMotion?: MouseMotion } => {
1414
// Use a mouse icon if it's a mouse motion instead of a key
1515
if (typeof labeledKeyOrMouseMotion === "string") return { mouseMotion: labeledKeyOrMouseMotion };
1616
@@ -33,11 +33,25 @@
3333
});
3434
3535
// Consolidate consecutive labels into a concatenated single label
36-
const consolidatedList: typeof list = [];
37-
list.forEach((item) => {
38-
const lastItem = consolidatedList[consolidatedList.length - 1];
39-
if (item.label && lastItem?.label) lastItem.label += " " + item.label;
40-
else consolidatedList.push(item);
36+
const consolidatedList: ReturnType<typeof keyTextOrIconList> = [];
37+
list.forEach((currentItem) => {
38+
const lastGroup = consolidatedList.length > 0 ? consolidatedList[consolidatedList.length - 1] : undefined;
39+
const lastItem = lastGroup !== undefined ? lastGroup[lastGroup.length - 1] : undefined;
40+
41+
// If current and last are both labels, concatenate both within their existing label
42+
if (currentItem.label && lastItem && "label" in lastItem && lastItem.label) {
43+
lastItem.label += " " + currentItem.label;
44+
return;
45+
}
46+
47+
// If current and last are both of the same group type (both icons/labels, or both mouseMotion), join them within their existing
48+
if (lastItem && (((currentItem.label || currentItem.icon) && ("label" in lastItem || "icon" in lastItem)) || (currentItem.mouseMotion && "mouseMotion" in lastItem))) {
49+
lastGroup?.push(currentItem);
50+
return;
51+
}
52+
53+
// Otherwise, start a new group with the first item of its group type
54+
consolidatedList.push([currentItem]);
4155
});
4256
return consolidatedList;
4357
}
@@ -73,32 +87,38 @@
7387
}
7488
}
7589
76-
function mouseHintIcon(input?: MouseMotion): IconName {
90+
function mouseHintIcon(input: MouseMotion): IconName {
7791
return `MouseHint${input}` as IconName;
7892
}
7993
</script>
8094

8195
<LayoutRow class="shortcut-label">
82-
{#each keyTextOrIconList(shortcut.shortcut) as { label, icon, mouseMotion }}
83-
{#if label}
96+
{#each keyTextOrIconList(shortcut.shortcut) as group}
97+
{#if "label" in group[0] || "icon" in group[0]}
8498
<div class="key-label">
85-
<TextLabel>{label}</TextLabel>
86-
</div>
87-
{:else if icon}
88-
<div class="key-icon">
89-
<IconLabel {icon} />
90-
</div>
91-
{:else if mouseMotion}
92-
<div class="mouse-icon">
93-
<IconLabel icon={mouseHintIcon(mouseMotion)} />
99+
{#each group as item}
100+
{#if "label" in item && item.label}
101+
<TextLabel>{item.label}</TextLabel>
102+
{:else if "icon" in item && item.icon}
103+
<IconLabel icon={item.icon} />
104+
{/if}
105+
{/each}
94106
</div>
95107
{/if}
108+
{#if "mouseMotion" in group[0]}
109+
{#each group as item}
110+
{#if "mouseMotion" in item && item.mouseMotion}
111+
<div class="mouse-icon">
112+
<IconLabel icon={mouseHintIcon(item.mouseMotion)} />
113+
</div>
114+
{/if}
115+
{/each}
116+
{/if}
96117
{/each}
97118
</LayoutRow>
98119

99120
<style lang="scss" global>
100121
.shortcut-label {
101-
.key-icon,
102122
.key-label {
103123
display: flex;
104124
align-items: center;
@@ -108,6 +128,10 @@
108128
background: var(--color-3-darkgray);
109129
color: var(--color-b-lightgray);
110130
fill: var(--color-b-lightgray);
131+
132+
* + * {
133+
margin-left: 4px;
134+
}
111135
}
112136
113137
svg {
@@ -120,7 +144,6 @@
120144
121145
.floating-menu-content .row > & {
122146
.key-label,
123-
.key-icon,
124147
.mouse-icon {
125148
color: var(--color-8-uppergray);
126149
background: none;
@@ -134,7 +157,7 @@
134157
}
135158
}
136159
137-
.key-icon svg {
160+
.key-label svg {
138161
fill: var(--color-8-uppergray);
139162
}
140163

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
3434
export let tabMinWidths = false;
3535
export let tabCloseButtons = false;
36-
export let tabLabels: { name: string; unsaved?: boolean; tooltipDescription?: string; tooltipShortcut?: string }[];
36+
export let tabLabels: { name: string; unsaved?: boolean; tooltipLabel?: string; tooltipDescription?: string; tooltipShortcut?: string }[];
3737
export let tabActiveIndex: number;
3838
export let panelType: PanelType | undefined = undefined;
3939
export let clickAction: ((index: number) => void) | undefined = undefined;
@@ -67,7 +67,7 @@
6767
<LayoutRow
6868
class="tab"
6969
classes={{ active: tabIndex === tabActiveIndex }}
70-
tooltipLabel={tabLabel.name}
70+
tooltipLabel={tabLabel.tooltipLabel}
7171
tooltipDescription={tabLabel.tooltipDescription}
7272
on:click={(e) => {
7373
e.stopPropagation();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
if (!editor.handle.inDevelopmentMode()) return { name, unsaved };
3434
3535
const tooltipDescription = `Document ID: ${doc.id}`;
36-
return { name, unsaved, tooltipDescription };
36+
return { name, unsaved, tooltipLabel: name, tooltipDescription };
3737
});
3838
3939
const editor = getContext<Editor>("editor");

0 commit comments

Comments
 (0)