PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
fix(ui): preserve selection clearing semantics after format application
Combiler016de633973627
diff --git a/crates/ui-egui/src/panels/edit.rs b/crates/ui-egui/src/panels/edit.rsindex 65b294bc8..71a53eddd 100644--- a/crates/ui-egui/src/panels/edit.rs+++ b/crates/ui-egui/src/panels/edit.rs@@ -462,7 +462,6 @@ impl PdfCraftApp {/// Apply the open paragraph's formatting as one change; the paragraph stays open.pub(crate) fn apply_line_format(&mut self, index: usize, mut ed: crate::edit_text_ui::LineEditor, ctx: Option<&egui::Context>) {let edit = pdfcraft_engine::Edit::EditTextBlock { page: ed.page, block: ed.block, text: ed.text.clone(), style: ed.style() };- let sel = ed.selection.clone();if self.apply_edit(edit) {ed.applied();if let Some(doc) = self.session.get(self.views[index].id)@@ -473,9 +472,6 @@ impl PdfCraftApp {ed.fonts = crate::edit_text_ui::install_source_fonts(ctx, doc, ed.page);}}- if sel.is_some() {- ed.selection = sel;- }}self.views[index].line_editor = Some(ed);}diff --git a/crates/ui-egui/tests/it/editing.rs b/crates/ui-egui/tests/it/editing.rsindex 922b6fde4..9d7198596 100644--- a/crates/ui-egui/tests/it/editing.rs+++ b/crates/ui-egui/tests/it/editing.rs@@ -4795,6 +4795,12 @@ fn the_format_panel_toggles_superscript_and_subscript_on_selection() {assert_eq!(doc.can_undo(), Some("Edit text"));assert_eq!(doc.text_blocks(0)[0].text, "Page ¹");+ // Select "¹" in "Page ¹" to toggle it back:+ let ed = h.state_mut().views[0].line_editor.as_mut().unwrap();+ ed.selection = Some(5..7);+ ed.focus = true;+ h.run_steps(1);+// Click Superscript again: "¹" toggles back to "1"h.get_by_label("Superscript").click();h.run_steps(4);