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.
This commit is contained in:
parent
8e48bf02a0
commit
02f70ab0b3
3 changed files with 12 additions and 10 deletions
|
|
@ -628,15 +628,15 @@ impl super::OpenCADStudio {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Commit the editor — create a new MText or update the edited one.
|
/// 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 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 body_empty = ed.content.text().trim().is_empty();
|
||||||
let mt = ed.build_mtext();
|
let mt = ed.build_mtext();
|
||||||
if body_empty {
|
if body_empty {
|
||||||
// Empty content: drop a new entity; leave an edited one untouched.
|
// Empty content: drop a new entity; leave an edited one untouched.
|
||||||
self.refresh_properties();
|
self.refresh_properties();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if let Some(h) = ed.editing {
|
if let Some(h) = ed.editing {
|
||||||
self.push_undo_snapshot(i, "MTEXT");
|
self.push_undo_snapshot(i, "MTEXT");
|
||||||
|
|
@ -666,6 +666,7 @@ impl super::OpenCADStudio {
|
||||||
self.tabs[i].dirty = true;
|
self.tabs[i].dirty = true;
|
||||||
}
|
}
|
||||||
self.refresh_properties();
|
self.refresh_properties();
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Discard the editor without changing the drawing.
|
/// Discard the editor without changing the drawing.
|
||||||
|
|
|
||||||
|
|
@ -194,12 +194,12 @@ impl super::OpenCADStudio {
|
||||||
|
|
||||||
/// Commit the editor: create a new TEXT entity or update the edited slot.
|
/// 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.
|
/// 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 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() {
|
if ed.value.trim().is_empty() && ed.editing.is_none() {
|
||||||
self.refresh_properties();
|
self.refresh_properties();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
if let Some(h) = ed.editing {
|
if let Some(h) = ed.editing {
|
||||||
self.push_undo_snapshot(i, "TEXT");
|
self.push_undo_snapshot(i, "TEXT");
|
||||||
|
|
@ -230,6 +230,7 @@ impl super::OpenCADStudio {
|
||||||
self.tabs[i].dirty = true;
|
self.tabs[i].dirty = true;
|
||||||
}
|
}
|
||||||
self.refresh_properties();
|
self.refresh_properties();
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Discard the editor without changing the drawing.
|
/// Discard the editor without changing the drawing.
|
||||||
|
|
|
||||||
|
|
@ -4693,8 +4693,8 @@ impl OpenCADStudio {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
Message::MTextOk => {
|
Message::MTextOk => {
|
||||||
self.mtext_commit();
|
let committed = self.mtext_commit();
|
||||||
self.post_editor_closed(true)
|
self.post_editor_closed(committed)
|
||||||
}
|
}
|
||||||
Message::MTextCancel => {
|
Message::MTextCancel => {
|
||||||
self.mtext_cancel();
|
self.mtext_cancel();
|
||||||
|
|
@ -4708,8 +4708,8 @@ impl OpenCADStudio {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
Message::TextInlineOk => {
|
Message::TextInlineOk => {
|
||||||
self.text_inline_commit();
|
let committed = self.text_inline_commit();
|
||||||
self.post_editor_closed(true)
|
self.post_editor_closed(committed)
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::DrawOrderSubmenuToggle => {
|
Message::DrawOrderSubmenuToggle => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue