Skip to content

Commit 8ca546c

Browse files
Fix using Esc to abort box selection and wire dragging causing the graph to close (#3409)
* Implement proper node graph interaction aborting when pressing Escape * Fixes --------- Co-authored-by: Keavon Chambers <[email protected]>
1 parent 2ee8e56 commit 8ca546c

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

editor/src/messages/input_mapper/input_mappings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ pub fn input_mappings() -> Mapping {
325325
//
326326
// DocumentMessage
327327
entry!(KeyDown(Space); modifiers=[Control], action_dispatch=DocumentMessage::GraphViewOverlayToggle),
328-
entry!(KeyUp(Escape); action_dispatch=DocumentMessage::Escape),
328+
entry!(KeyDownNoRepeat(Escape); action_dispatch=DocumentMessage::Escape),
329329
entry!(KeyDown(Delete); action_dispatch=DocumentMessage::DeleteSelectedLayers),
330330
entry!(KeyDown(Backspace); action_dispatch=DocumentMessage::DeleteSelectedLayers),
331331
entry!(KeyDown(KeyO); modifiers=[Alt], action_dispatch=DocumentMessage::ToggleOverlaysVisibility),

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::messages::layout::utility_types::widget_prelude::*;
1212
use crate::messages::portfolio::document::data_panel::{DataPanelMessageContext, DataPanelMessageHandler};
1313
use crate::messages::portfolio::document::graph_operation::utility_types::TransformIn;
1414
use crate::messages::portfolio::document::node_graph::NodeGraphMessageContext;
15+
use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType;
1516
use crate::messages::portfolio::document::overlays::grid_overlays::{grid_overlay, overlay_options};
1617
use crate::messages::portfolio::document::overlays::utility_types::{OverlaysType, OverlaysVisibilitySettings};
1718
use crate::messages::portfolio::document::properties_panel::properties_panel_message_handler::PropertiesPanelMessageContext;
@@ -476,25 +477,44 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
476477
responses.add(NodeGraphMessage::UpdateNodeGraphWidth);
477478
}
478479
DocumentMessage::Escape => {
480+
// Abort dragging nodes
479481
if self.node_graph_handler.drag_start.is_some() {
480482
responses.add(DocumentMessage::AbortTransaction);
481483
self.node_graph_handler.drag_start = None;
482-
} else if self
484+
}
485+
// Abort box selection
486+
else if self.node_graph_handler.box_selection_start.is_some() {
487+
self.node_graph_handler.box_selection_start = None;
488+
responses.add(NodeGraphMessage::SelectedNodesSet {
489+
nodes: self.node_graph_handler.selection_before_pointer_down.clone(),
490+
});
491+
responses.add(FrontendMessage::UpdateBox { box_selection: None });
492+
}
493+
// Abort wire in progress of being connected
494+
else if self.node_graph_handler.wire_in_progress_from_connector.is_some() {
495+
self.node_graph_handler.wire_in_progress_from_connector = None;
496+
self.node_graph_handler.wire_in_progress_to_connector = None;
497+
self.node_graph_handler.wire_in_progress_type = FrontendGraphDataType::General;
498+
499+
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
500+
responses.add(DocumentMessage::AbortTransaction);
501+
}
502+
// Close the context menu if it's open
503+
else if self
483504
.node_graph_handler
484505
.context_menu
485506
.as_ref()
486507
.is_some_and(|context_menu| matches!(context_menu.context_menu_data, super::node_graph::utility_types::ContextMenuData::CreateNode { compatible_type: None }))
487508
{
488-
// Close the context menu
489509
self.node_graph_handler.context_menu = None;
490510
responses.add(FrontendMessage::UpdateContextMenuInformation { context_menu_information: None });
491-
self.node_graph_handler.wire_in_progress_from_connector = None;
492-
self.node_graph_handler.wire_in_progress_to_connector = None;
493-
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
494-
} else if !self.breadcrumb_network_path.is_empty() {
495-
// Exit one level up if inside a nested network
511+
}
512+
// Exit one level up if inside a nested network
513+
else if !self.breadcrumb_network_path.is_empty() {
496514
responses.add(DocumentMessage::ExitNestedNetwork { steps_back: 1 });
497-
} else {
515+
}
516+
// Close the graph view overlay if it's open
517+
else {
498518
responses.add(DocumentMessage::GraphViewOverlay { open: false });
499519
}
500520
}

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,21 @@ pub struct NodeGraphMessageHandler {
6363
pub drag_start_chain_nodes: Vec<NodeId>,
6464
/// If dragging the background to create a box selection, this stores its starting point in node graph coordinates,
6565
/// plus a flag indicating if it has been dragged since the mousedown began.
66-
box_selection_start: Option<(DVec2, bool)>,
66+
pub box_selection_start: Option<(DVec2, bool)>,
6767
/// Restore the selection before box selection if it is aborted
68-
selection_before_pointer_down: Vec<NodeId>,
68+
pub selection_before_pointer_down: Vec<NodeId>,
6969
/// If the grip icon is held during a drag, then shift without pushing other nodes
7070
shift_without_push: bool,
7171
disconnecting: Option<InputConnector>,
7272
initial_disconnecting: bool,
7373
/// Node to select on pointer up if multiple nodes are selected and they were not dragged.
7474
select_if_not_dragged: Option<NodeId>,
75-
/// The start of the dragged line (cannot be moved), stored in node graph coordinates
75+
/// The start of the dragged line (cannot be moved), stored in node graph coordinates.
7676
pub wire_in_progress_from_connector: Option<DVec2>,
77-
wire_in_progress_type: FrontendGraphDataType,
78-
/// The end point of the dragged line (cannot be moved), stored in node graph coordinates
77+
/// The end point of the dragged line (cannot be moved), stored in node graph coordinates.
7978
pub wire_in_progress_to_connector: Option<DVec2>,
79+
/// The data type determining the color of the wire being dragged.
80+
pub wire_in_progress_type: FrontendGraphDataType,
8081
/// State for the context menu popups.
8182
pub context_menu: Option<ContextMenuInformation>,
8283
/// Index of selected node to be deselected on pointer up when shift clicking an already selected node
@@ -295,8 +296,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
295296
}
296297

297298
self.wire_in_progress_from_connector = None;
298-
self.wire_in_progress_type = FrontendGraphDataType::General;
299299
self.wire_in_progress_to_connector = None;
300+
self.wire_in_progress_type = FrontendGraphDataType::General;
300301
}
301302
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
302303
responses.add(FrontendMessage::UpdateContextMenuInformation {
@@ -768,8 +769,9 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
768769
// Abort dragging a wire
769770
if self.wire_in_progress_from_connector.is_some() {
770771
self.wire_in_progress_from_connector = None;
771-
self.wire_in_progress_type = FrontendGraphDataType::General;
772772
self.wire_in_progress_to_connector = None;
773+
self.wire_in_progress_type = FrontendGraphDataType::General;
774+
773775
responses.add(DocumentMessage::AbortTransaction);
774776
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
775777
return;
@@ -850,8 +852,9 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
850852
if self.context_menu.is_some() {
851853
self.context_menu = None;
852854
self.wire_in_progress_from_connector = None;
853-
self.wire_in_progress_type = FrontendGraphDataType::General;
854855
self.wire_in_progress_to_connector = None;
856+
self.wire_in_progress_type = FrontendGraphDataType::General;
857+
855858
responses.add(FrontendMessage::UpdateContextMenuInformation {
856859
context_menu_information: self.context_menu.clone(),
857860
});
@@ -1388,14 +1391,18 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
13881391
});
13891392
responses.add(DocumentMessage::EndTransaction);
13901393
}
1394+
13911395
self.drag_start = None;
13921396
self.begin_dragging = false;
13931397
self.box_selection_start = None;
1398+
13941399
self.wire_in_progress_from_connector = None;
1395-
self.wire_in_progress_type = FrontendGraphDataType::General;
13961400
self.wire_in_progress_to_connector = None;
1401+
self.wire_in_progress_type = FrontendGraphDataType::General;
1402+
13971403
self.reordering_export = None;
13981404
self.reordering_import = None;
1405+
13991406
responses.add(DocumentMessage::EndTransaction);
14001407
responses.add(FrontendMessage::UpdateWirePathInProgress { wire_path: None });
14011408
responses.add(FrontendMessage::UpdateBox { box_selection: None });

0 commit comments

Comments
 (0)