Skip to content

Commit

Permalink
Delete Empty Text Layer on Escape or Right Click
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidharth-Singh10 committed Dec 21, 2024
1 parent 2d77dcb commit 6ecc336
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions editor/src/messages/input_mapper/input_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ pub fn input_mappings() -> Mapping {
// TextToolMessage
entry!(KeyUp(MouseLeft); action_dispatch=TextToolMessage::Interact),
entry!(KeyDown(Escape); action_dispatch=TextToolMessage::CommitText),
entry!(KeyUp(MouseRight); action_dispatch=TextToolMessage::CommitText),
entry!(KeyDown(Enter); modifiers=[Accel], action_dispatch=TextToolMessage::CommitText),
//
// GradientToolMessage
Expand Down
15 changes: 14 additions & 1 deletion editor/src/messages/tool/tool_messages/text_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,21 @@ impl Fsm for TextToolFsmState {
TextToolFsmState::Ready
}
(TextToolFsmState::Editing, TextToolMessage::CommitText) => {
responses.add(FrontendMessage::TriggerTextCommit);
if tool_data.new_text.is_empty() {
// Remove the editable textbox UI first
tool_data.set_editing(false, font_cache, responses);

// Delete the empty text layer and update the graph
responses.add(NodeGraphMessage::DeleteNodes {
node_ids: vec![tool_data.layer.to_node()],
delete_children: true,
});
responses.add(NodeGraphMessage::RunDocumentGraph);

return TextToolFsmState::Ready;
}

responses.add(FrontendMessage::TriggerTextCommit);
TextToolFsmState::Editing
}
(TextToolFsmState::Editing, TextToolMessage::TextChange { new_text }) => {
Expand Down

0 comments on commit 6ecc336

Please sign in to comment.