From 1204f376e78d277c7eb7dcec9deea71c09d4a6b3 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 20 Nov 2026 05:35:02 -0500 Subject: [PATCH] Preserve menu ownership and composition undo --- crates/ui-egui/src/panels/pages.rs | 3 ++- crates/ui-egui/src/tools/edit_text_ui.rs | 25 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/pages.rs b/crates/ui-egui/src/panels/pages.rs index 40e407c84f..960c0ac0e7 100644 --- a/crates/ui-egui/src/panels/pages.rs +++ b/crates/ui-egui/src/panels/pages.rs @@ -83,7 +83,8 @@ pub(super) fn body(app: &mut PdfCraftApp, ui: &mut egui::Ui) -> PanelResult { result.edit = Some(pdfcraft_engine::Edit::MovePages { pages, to }); } ThumbnailEvent::Delete(_) => { - if editable { + // The menu bar owns keys while its menu is open, even over the thumbnails. + if editable && !craft::ui::menu::bar::is_open(ui.ctx()) { result.edit = delete_pages(view, count); } } diff --git a/crates/ui-egui/src/tools/edit_text_ui.rs b/crates/ui-egui/src/tools/edit_text_ui.rs index 9d82a2613d..9a8deec998 100644 --- a/crates/ui-egui/src/tools/edit_text_ui.rs +++ b/crates/ui-egui/src/tools/edit_text_ui.rs @@ -131,6 +131,8 @@ pub(crate) struct TypingHistory { history: EditHistory, /// The box as of its last record, the `before` of the next one. current: Typed, + /// The text before the first provisional IME composition update. + composition_before: Option, run: Option, next_gesture: GestureId, /// Each text the box has shown through its own typing, with its rows' alignments then, oldest @@ -141,7 +143,14 @@ pub(crate) struct TypingHistory { impl TypingHistory { /// A history that starts at `text`. pub(crate) fn new(text: Typed) -> Self { - TypingHistory { history: EditHistory::new(&text), current: text, run: None, next_gesture: GestureId::new(0), seen: Vec::new() } + TypingHistory { + history: EditHistory::new(&text), + current: text, + composition_before: None, + run: None, + next_gesture: GestureId::new(0), + seen: Vec::new(), + } } /// The box went to `now` through an edit of `kind`. Its aligns are already followed to the new @@ -152,6 +161,7 @@ impl TypingHistory { self.remember(&now.text, &now.aligns); match kind { EditKind::Typed | EditKind::Deleted => { + self.composition_before = None; if self.run.as_ref().is_none_or(|run| run.kind != kind) { self.end_run(&before); let id = self.next_gesture; @@ -162,9 +172,18 @@ impl TypingHistory { } } // The marked text of a composition is in the box but no step: its commit is the one. - EditKind::Composing => self.end_run(&before), + EditKind::Composing => { + self.end_run(&before); + self.composition_before.get_or_insert(before); + } _ => { self.end_run(&before); + let before = if kind == EditKind::Committed { + self.composition_before.take().unwrap_or(before) + } else { + self.composition_before = None; + before + }; self.history.record(&EditEvent::set(Mixed::Same(before), now, Arc::from(""), None)); } } @@ -182,6 +201,7 @@ impl TypingHistory { } self.follow_rows(&before, now); self.current = now.clone(); + self.composition_before = None; true } @@ -196,6 +216,7 @@ impl TypingHistory { pub(crate) fn restart(&mut self, now: Typed) { self.history = EditHistory::new(&now); self.current = now; + self.composition_before = None; self.run = None; self.seen.clear(); }