From 02f70ab0b30d583e86e104eb9ef829c73cd3cae2 Mon Sep 17 00:00:00 2001 From: Karim Jerbi Date: Thu, 18 Jun 2026 17:55:30 +0100 Subject: [PATCH] fix(editor): prevent empty text commit from advancing command edit_count - Propagates commit status out of inline editors so commands know whether a real change occurred. - Fixes TEXTEDIT's Undo step rolling back unrelated document actions when the user presses OK on empty/cleared existing MText. --- src/app/mtext_editor.rs | 7 ++++--- src/app/text_inline.rs | 7 ++++--- src/app/update.rs | 8 ++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/app/mtext_editor.rs b/src/app/mtext_editor.rs index e2422391e..aff2713d3 100644 --- a/src/app/mtext_editor.rs +++ b/src/app/mtext_editor.rs @@ -628,15 +628,15 @@ impl super::OpenCADStudio { } /// Commit the editor — create a new MText or update the edited one. - pub(super) fn mtext_commit(&mut self) { + pub(super) fn mtext_commit(&mut self) -> bool { let i = self.active_tab; - let Some(ed) = self.mtext_editor.take() else { return }; + let Some(ed) = self.mtext_editor.take() else { return false }; let body_empty = ed.content.text().trim().is_empty(); let mt = ed.build_mtext(); if body_empty { // Empty content: drop a new entity; leave an edited one untouched. self.refresh_properties(); - return; + return false; } if let Some(h) = ed.editing { self.push_undo_snapshot(i, "MTEXT"); @@ -666,6 +666,7 @@ impl super::OpenCADStudio { self.tabs[i].dirty = true; } self.refresh_properties(); + true } /// Discard the editor without changing the drawing. diff --git a/src/app/text_inline.rs b/src/app/text_inline.rs index c9a1c5356..e66470631 100644 --- a/src/app/text_inline.rs +++ b/src/app/text_inline.rs @@ -194,12 +194,12 @@ impl super::OpenCADStudio { /// Commit the editor: create a new TEXT entity or update the edited slot. /// Empty content drops a new entity and leaves an edited one untouched. - pub(super) fn text_inline_commit(&mut self) { + pub(super) fn text_inline_commit(&mut self) -> bool { let i = self.active_tab; - let Some(ed) = self.text_inline.take() else { return }; + let Some(ed) = self.text_inline.take() else { return false }; if ed.value.trim().is_empty() && ed.editing.is_none() { self.refresh_properties(); - return; + return false; } if let Some(h) = ed.editing { self.push_undo_snapshot(i, "TEXT"); @@ -230,6 +230,7 @@ impl super::OpenCADStudio { self.tabs[i].dirty = true; } self.refresh_properties(); + true } /// Discard the editor without changing the drawing. diff --git a/src/app/update.rs b/src/app/update.rs index 08bb128c7..a66776383 100644 --- a/src/app/update.rs +++ b/src/app/update.rs @@ -4693,8 +4693,8 @@ impl OpenCADStudio { Task::none() } Message::MTextOk => { - self.mtext_commit(); - self.post_editor_closed(true) + let committed = self.mtext_commit(); + self.post_editor_closed(committed) } Message::MTextCancel => { self.mtext_cancel(); @@ -4708,8 +4708,8 @@ impl OpenCADStudio { Task::none() } Message::TextInlineOk => { - self.text_inline_commit(); - self.post_editor_closed(true) + let committed = self.text_inline_commit(); + self.post_editor_closed(committed) } Message::DrawOrderSubmenuToggle => {