From d6925387363f30e09b566187572f73708dc80a43 Mon Sep 17 00:00:00 2001 From: mTvare Date: Mon, 13 Jan 2025 07:47:44 +0530 Subject: [PATCH] Make the Text tool delete empty text layers when clicking away wth LMB (#2192) Fix additions of layers when using left click Fixes: https://discord.com/channels/731730685944922173/881073965047636018/1327376421034922045 --- editor/src/messages/tool/tool_messages/text_tool.rs | 6 +++--- frontend/src/io-managers/input.ts | 4 ++-- frontend/wasm/src/editor_api.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/editor/src/messages/tool/tool_messages/text_tool.rs b/editor/src/messages/tool/tool_messages/text_tool.rs index 52dd6577..11509d69 100644 --- a/editor/src/messages/tool/tool_messages/text_tool.rs +++ b/editor/src/messages/tool/tool_messages/text_tool.rs @@ -63,7 +63,7 @@ pub enum TextToolMessage { Interact, PointerMove { center: Key, lock_ratio: Key }, PointerOutsideViewport { center: Key, lock_ratio: Key }, - TextChange { new_text: String, is_right_click: bool }, + TextChange { new_text: String, is_left_or_right_click: bool }, UpdateBounds { new_text: String }, UpdateOptions(TextOptionsUpdate), } @@ -577,10 +577,10 @@ impl Fsm for TextToolFsmState { responses.add(FrontendMessage::TriggerTextCommit); TextToolFsmState::Editing } - (TextToolFsmState::Editing, TextToolMessage::TextChange { new_text, is_right_click }) => { + (TextToolFsmState::Editing, TextToolMessage::TextChange { new_text, is_left_or_right_click }) => { tool_data.new_text = new_text; - if !is_right_click { + if !is_left_or_right_click { tool_data.set_editing(false, font_cache, responses); responses.add(NodeGraphMessage::SetInput { diff --git a/frontend/src/io-managers/input.ts b/frontend/src/io-managers/input.ts index f67f56cf..50f6ec34 100644 --- a/frontend/src/io-managers/input.ts +++ b/frontend/src/io-managers/input.ts @@ -172,8 +172,8 @@ export function createInputManager(editor: Editor, dialog: DialogState, portfoli } if (!inTextInput && !inContextMenu) { - const isRightClick = e.button === 2; - if (textToolInteractiveInputElement) editor.handle.onChangeText(textInputCleanup(textToolInteractiveInputElement.innerText), isRightClick); + const isLeftOrRightClick = e.button === 2 || e.button === 0; + if (textToolInteractiveInputElement) editor.handle.onChangeText(textInputCleanup(textToolInteractiveInputElement.innerText), isLeftOrRightClick); else viewportPointerInteractionOngoing = isTargetingCanvas instanceof Element; } diff --git a/frontend/wasm/src/editor_api.rs b/frontend/wasm/src/editor_api.rs index d7663d7e..f620832c 100644 --- a/frontend/wasm/src/editor_api.rs +++ b/frontend/wasm/src/editor_api.rs @@ -433,8 +433,8 @@ impl EditorHandle { /// A text box was committed #[wasm_bindgen(js_name = onChangeText)] - pub fn on_change_text(&self, new_text: String, is_right_click: bool) -> Result<(), JsValue> { - let message = TextToolMessage::TextChange { new_text, is_right_click }; + pub fn on_change_text(&self, new_text: String, is_left_or_right_click: bool) -> Result<(), JsValue> { + let message = TextToolMessage::TextChange { new_text, is_left_or_right_click }; self.dispatch(message); Ok(())