Skip to content

Commit 2ee8e56

Browse files
committed
Fix sending platform-specific shortcut keys to frontend before editor is initialized with the platform set
1 parent 783ea0b commit 2ee8e56

File tree

12 files changed

+77
-52
lines changed

12 files changed

+77
-52
lines changed

editor/src/messages/frontend/frontend_message.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::utility_types::{DocumentDetails, MouseCursorIcon, OpenDocument};
22
use crate::messages::app_window::app_window_message_handler::AppWindowPlatform;
3+
use crate::messages::input_mapper::utility_types::misc::ActionShortcut;
34
use crate::messages::layout::utility_types::widget_prelude::*;
45
use crate::messages::portfolio::document::node_graph::utility_types::{
56
BoxSelection, ContextMenuInformation, FrontendClickTargets, FrontendGraphInput, FrontendGraphOutput, FrontendNode, FrontendNodeType, NodeGraphErrorDiagnostic, Transform,
@@ -58,6 +59,12 @@ pub enum FrontendMessage {
5859
#[serde(rename = "nodeTypes")]
5960
node_types: Vec<FrontendNodeType>,
6061
},
62+
SendShortcutF11 {
63+
shortcut: Option<ActionShortcut>,
64+
},
65+
SendShortcutAltClick {
66+
shortcut: Option<ActionShortcut>,
67+
},
6168

6269
// Trigger prefix: cause a browser API to do something
6370
TriggerAboutGraphiteLocalizedCommitDate {

editor/src/messages/input_mapper/utility_types/misc.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,11 @@ pub enum ActionShortcut {
136136

137137
impl ActionShortcut {
138138
pub fn realize_shortcut(&mut self, action_input_mapping: &impl Fn(&MessageDiscriminant) -> Option<KeysGroup>) {
139-
match self {
140-
Self::Action(action) => {
141-
if let Some(keys) = action_input_mapping(action) {
142-
*self = Self::Shortcut(keys.into());
143-
} else {
144-
*self = Self::Shortcut(KeysGroup::default().into());
145-
}
146-
}
147-
Self::Shortcut(shortcut) => {
148-
warn!("Calling `.to_keys()` on a `ActionShortcut::Shortcut` is a mistake/bug. Shortcut is: {shortcut:?}.");
139+
if let Self::Action(action) = self {
140+
if let Some(keys) = action_input_mapping(action) {
141+
*self = Self::Shortcut(keys.into());
142+
} else {
143+
*self = Self::Shortcut(KeysGroup::default().into());
149144
}
150145
}
151146
}

editor/src/messages/layout/layout_message_handler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct LayoutMessageContext<'a> {
1313

1414
#[derive(Debug, Clone, Default, ExtractField)]
1515
pub struct LayoutMessageHandler {
16-
layouts: [Layout; LayoutTarget::LayoutTargetLength as usize],
16+
layouts: [Layout; LayoutTarget::_LayoutTargetLength as usize],
1717
}
1818

1919
#[message_handler_data]
@@ -518,7 +518,8 @@ impl LayoutMessageHandler {
518518
LayoutTarget::WelcomeScreenButtons => FrontendMessage::UpdateWelcomeScreenButtonsLayout { diff },
519519
LayoutTarget::WorkingColors => FrontendMessage::UpdateWorkingColorsLayout { diff },
520520

521-
LayoutTarget::LayoutTargetLength => panic!("`LayoutTargetLength` is not a valid Layout Target and is used for array indexing"),
521+
// KEEP THIS ENUM LAST
522+
LayoutTarget::_LayoutTargetLength => panic!("`_LayoutTargetLength` is not a valid `LayoutTarget` and is used for array indexing"),
522523
};
523524

524525
responses.add(message);

editor/src/messages/layout/utility_types/layout_widget.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub enum LayoutTarget {
5656

5757
// KEEP THIS ENUM LAST
5858
// This is a marker that is used to define an array that is used to hold widgets
59-
LayoutTargetLength,
59+
_LayoutTargetLength,
6060
}
6161

6262
/// For use by structs that define a UI widget layout by implementing the layout() function belonging to this trait.

editor/src/messages/portfolio/menu_bar/menu_bar_message_handler.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ impl LayoutHolder for MenuBarMessageHandler {
689689
.on_commit(|_| DebugMessage::ToggleTraceLogs.into()),
690690
MenuListEntry::new("Print Messages: Off")
691691
.label("Print Messages: Off")
692-
.icon(message_logging_verbosity_off.then_some({
692+
.icon(if message_logging_verbosity_off {
693693
#[cfg(not(target_os = "macos"))]
694694
{
695695
"SmallDot".to_string()
@@ -698,12 +698,12 @@ impl LayoutHolder for MenuBarMessageHandler {
698698
{
699699
"CheckboxChecked".to_string()
700700
}
701-
}).unwrap_or_default())
701+
} else { Default::default() })
702702
.tooltip_shortcut(action_shortcut!(DebugMessageDiscriminant::MessageOff))
703703
.on_commit(|_| DebugMessage::MessageOff.into()),
704704
MenuListEntry::new("Print Messages: Only Names")
705705
.label("Print Messages: Only Names")
706-
.icon(message_logging_verbosity_names.then_some({
706+
.icon(if message_logging_verbosity_names {
707707
#[cfg(not(target_os = "macos"))]
708708
{
709709
"SmallDot".to_string()
@@ -712,12 +712,12 @@ impl LayoutHolder for MenuBarMessageHandler {
712712
{
713713
"CheckboxChecked".to_string()
714714
}
715-
}).unwrap_or_default())
715+
} else { Default::default() })
716716
.tooltip_shortcut(action_shortcut!(DebugMessageDiscriminant::MessageNames))
717717
.on_commit(|_| DebugMessage::MessageNames.into()),
718718
MenuListEntry::new("Print Messages: Full Contents")
719719
.label("Print Messages: Full Contents")
720-
.icon(message_logging_verbosity_contents.then_some({
720+
.icon(if message_logging_verbosity_contents {
721721
#[cfg(not(target_os = "macos"))]
722722
{
723723
"SmallDot".to_string()
@@ -726,7 +726,7 @@ impl LayoutHolder for MenuBarMessageHandler {
726726
{
727727
"CheckboxChecked".to_string()
728728
}
729-
}).unwrap_or_default())
729+
} else { Default::default() })
730730
.tooltip_shortcut(action_shortcut!(DebugMessageDiscriminant::MessageContents))
731731
.on_commit(|_| DebugMessage::MessageContents.into()),
732732
],

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use crate::messages::animation::TimingInformation;
77
use crate::messages::debug::utility_types::MessageLoggingVerbosity;
88
use crate::messages::dialog::simple_dialogs;
99
use crate::messages::frontend::utility_types::{DocumentDetails, OpenDocument};
10-
use crate::messages::input_mapper::utility_types::macros::action_shortcut;
10+
use crate::messages::input_mapper::utility_types::input_keyboard::Key;
11+
use crate::messages::input_mapper::utility_types::macros::{action_shortcut, action_shortcut_manual};
1112
use crate::messages::layout::utility_types::widget_prelude::*;
1213
use crate::messages::portfolio::document::DocumentMessageContext;
1314
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
@@ -154,6 +155,17 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
154155
node_types: document_node_definitions::collect_node_types(),
155156
});
156157

158+
// Send shortcuts for widgets created in the frontend which need shortcut tooltips
159+
responses.add(FrontendMessage::SendShortcutF11 {
160+
shortcut: action_shortcut_manual!(Key::F11),
161+
});
162+
responses.add(FrontendMessage::SendShortcutAltClick {
163+
shortcut: action_shortcut_manual!(Key::Alt, Key::MouseLeft),
164+
});
165+
166+
// Before loading any documents, initially prepare the welcome screen buttons layout
167+
responses.add(PortfolioMessage::RequestWelcomeScreenButtonsLayout);
168+
157169
// Tell frontend to finish loading persistent documents
158170
responses.add(FrontendMessage::TriggerLoadRestAutoSaveDocuments);
159171

@@ -1117,7 +1129,14 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
11171129
})
11181130
})
11191131
.collect::<Vec<_>>();
1132+
1133+
let no_open_documents = open_documents.is_empty();
1134+
11201135
responses.add(FrontendMessage::UpdateOpenDocumentsList { open_documents });
1136+
1137+
if no_open_documents {
1138+
responses.add(PortfolioMessage::RequestWelcomeScreenButtonsLayout);
1139+
}
11211140
}
11221141
PortfolioMessage::UpdateVelloPreference => {
11231142
let active = if cfg!(target_family = "wasm") { false } else { preferences.use_vello };

editor/src/messages/tool/utility_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ impl HintData {
533533
for shortcut in &hint.key_groups {
534534
widgets.push(ShortcutLabel::new(Some(ActionShortcut::Shortcut(shortcut.clone()))).widget_instance());
535535
}
536-
if let Some(mouse_movement) = &hint.mouse {
537-
let mouse_movement = LabeledShortcut(vec![LabeledKeyOrMouseMotion::MouseMotion(mouse_movement.clone())]);
536+
if let Some(mouse_movement) = hint.mouse {
537+
let mouse_movement = LabeledShortcut(vec![LabeledKeyOrMouseMotion::MouseMotion(mouse_movement)]);
538538
let shortcut = ActionShortcut::Shortcut(mouse_movement);
539539
widgets.push(ShortcutLabel::new(Some(shortcut)).widget_instance());
540540
}

frontend/src/components/panels/Layers.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts">
22
import { getContext, onMount, onDestroy, tick } from "svelte";
33
4-
import { shortcutAltClick } from "@graphite/../wasm/pkg/graphite_wasm";
54
import type { Editor } from "@graphite/editor";
65
import {
76
patchLayout,
@@ -10,6 +9,7 @@
109
UpdateLayersPanelControlBarLeftLayout,
1110
UpdateLayersPanelControlBarRightLayout,
1211
UpdateLayersPanelBottomBarLayout,
12+
SendShortcutAltClick,
1313
} from "@graphite/messages";
1414
import type { ActionShortcut, DataBuffer, LayerPanelEntry, Layout } from "@graphite/messages";
1515
import type { NodeGraphState } from "@graphite/state-providers/node-graph";
@@ -73,9 +73,13 @@
7373
let layersPanelControlBarRightLayout: Layout = [];
7474
let layersPanelBottomBarLayout: Layout = [];
7575
76-
const altClickKeys: ActionShortcut = shortcutAltClick();
76+
let altClickShortcut: ActionShortcut | undefined;
7777
7878
onMount(() => {
79+
editor.subscriptions.subscribeJsMessage(SendShortcutAltClick, async (data) => {
80+
altClickShortcut = data.shortcut;
81+
});
82+
7983
editor.subscriptions.subscribeJsMessage(UpdateLayersPanelControlBarLeftLayout, (updateLayersPanelControlBarLeftLayout) => {
8084
patchLayout(layersPanelControlBarLeftLayout, updateLayersPanelControlBarLeftLayout);
8185
layersPanelControlBarLeftLayout = layersPanelControlBarLeftLayout;
@@ -624,7 +628,7 @@
624628
? "Hide the layers nested within. (To affect all open descendants, perform the shortcut shown.)"
625629
: "Show the layers nested within. (To affect all closed descendants, perform the shortcut shown.)") +
626630
(listing.entry.ancestorOfSelected && !listing.entry.expanded ? "\n\nNote: a selected layer is currently contained within.\n" : "")}
627-
data-tooltip-shortcut={altClickKeys?.shortcut ? JSON.stringify(altClickKeys.shortcut) : undefined}
631+
data-tooltip-shortcut={altClickShortcut?.shortcut ? JSON.stringify(altClickShortcut.shortcut) : undefined}
628632
on:click={(e) => handleExpandArrowClickWithModifiers(e, listing.entry.id)}
629633
tabindex="0"
630634
></button>
@@ -636,7 +640,7 @@
636640
icon="Clipped"
637641
class="clipped-arrow"
638642
tooltipDescription="Clipping mask is active. To release it, perform the shortcut on the layer border."
639-
tooltipShortcut={altClickKeys}
643+
tooltipShortcut={altClickShortcut}
640644
/>
641645
{/if}
642646
<div class="thumbnail">

frontend/src/components/panels/Welcome.svelte

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
patchLayout(welcomePanelButtonsLayout, updateWelcomeScreenButtonsLayout);
2222
welcomePanelButtonsLayout = welcomePanelButtonsLayout;
2323
});
24-
25-
editor.handle.requestWelcomeScreenButtonsLayout();
2624
});
2725
2826
onDestroy(() => {

frontend/src/components/window/title-bar/WindowButtonsWeb.svelte

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
<script lang="ts">
2-
import { getContext } from "svelte";
2+
import { getContext, onMount } from "svelte";
33
4-
import { shortcutF11 } from "@graphite/../wasm/pkg/graphite_wasm";
4+
import type { Editor } from "@graphite/editor";
55
import type { ActionShortcut } from "@graphite/messages";
6+
import { SendShortcutF11 } from "@graphite/messages";
67
import type { FullscreenState } from "@graphite/state-providers/fullscreen";
78
89
import LayoutRow from "@graphite/components/layout/LayoutRow.svelte";
910
import IconLabel from "@graphite/components/widgets/labels/IconLabel.svelte";
1011
1112
const fullscreen = getContext<FullscreenState>("fullscreen");
13+
const editor = getContext<Editor>("editor");
1214
13-
const f11Keys: ActionShortcut = shortcutF11();
15+
let f11Shortcut: ActionShortcut | undefined = undefined;
16+
17+
onMount(() => {
18+
editor.subscriptions.subscribeJsMessage(SendShortcutF11, async (data) => {
19+
f11Shortcut = data.shortcut;
20+
});
21+
});
1422
1523
async function handleClick() {
1624
if ($fullscreen.windowFullscreen) fullscreen.exitFullscreen();
@@ -23,7 +31,7 @@
2331
on:click={handleClick}
2432
tooltipLabel={$fullscreen.windowFullscreen ? "Exit Fullscreen" : "Enter Fullscreen"}
2533
tooltipDescription={$fullscreen.keyboardLockApiSupported ? "While fullscreen, keyboard shortcuts normally reserved by the browser become available." : ""}
26-
tooltipShortcut={f11Keys}
34+
tooltipShortcut={f11Shortcut}
2735
>
2836
<IconLabel icon={$fullscreen.windowFullscreen ? "FullscreenExit" : "FullscreenEnter"} />
2937
</LayoutRow>

0 commit comments

Comments
 (0)