From 032eab33c40aeb6fe0ff16250b03bfe01c6bd8a3 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Fri, 27 Nov 2026 18:33:10 +0000 Subject: [PATCH] The slide text editor takes focus when it opens; a clicked ribbon tab shows; outline body field is queried by its multi-line role; pattern colour opener is hovered before it is pressed Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/canvas/tests.rs | 5 --- crates/ui-egui/src/canvas/text_host.rs | 34 ++++++++++++------- .../ui-egui/src/panels/pattern_fill_tests.rs | 9 ++++- crates/ui-egui/src/ribbon.rs | 3 +- crates/ui-egui/src/ribbon/states.rs | 3 -- crates/ui-egui/src/sorter/ui_tests.rs | 6 ++-- 6 files changed, 35 insertions(+), 25 deletions(-) diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index b50d27ed2..3b2544f79 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -156,11 +156,6 @@ fn empty_bullet_preview_follows_click_type_enter_and_toggle() { h.run_steps(3); let second = caret(&h); assert!((first.x - second.x).abs() < 0.01, "empty lines retain the bullet indent"); - eprintln!( - "DIAG empty_bullet_preview_follows_click_type_enter_and_toggle: first {first:?} second {second:?} caret {:?} para count {:?}", - h.state().session.active().unwrap().selection.text.as_ref().map(|t| t.caret), - h.state().session.active().unwrap().shapes().iter().find(|s| s.id == id).map(|s| format!("{:?}", s.kind).len()) - ); assert!(second.y > first.y); let st = h.state().session.active().unwrap(); let ts = st.selection.text.as_ref().unwrap(); diff --git a/crates/ui-egui/src/canvas/text_host.rs b/crates/ui-egui/src/canvas/text_host.rs index ce56e0c77..713a5a10b 100644 --- a/crates/ui-egui/src/canvas/text_host.rs +++ b/crates/ui-egui/src/canvas/text_host.rs @@ -7,7 +7,10 @@ use craft::text::ui::editor::{ }; use craft::ui::canvas::CanvasSpace; use craft::ui::contract::{Bind, Props as _, Show as _}; -use craft::ui::runtime::{env::with_env, focus}; +use craft::ui::runtime::{ + env::with_env, + focus::{self, FocusRequest}, +}; use deckcraft_engine::{Session, TextReplaceKind, TextSel, cmd::text}; use deckcraft_geom::Affine; use deckcraft_model::text::TextBody; @@ -307,22 +310,29 @@ fn document_bounds(points: [deckcraft_geom::Point; 4], transform: Affine) -> Rec })) } -/// Hosts the edited shape or cell while no dialog, palette, File view or other text field owns input. +/// Hosts the edited shape or cell while no dialog, palette, File view or other text field owns input. The pass that +/// first shows an editor takes the focus for it, as a click that opens an inline editor does. pub(crate) fn show_editor(app: &mut crate::SlideApp, ui: &mut Ui, space: &CanvasSpace) -> Option { + let shown = egui::Id::new("slide-text-editor-shown"); + let before = ui.data(|data| data.get_temp::(shown)); + let hosted = host_editor(app, ui, space, before); + ui.data_mut(|data| match &hosted { + Some((_, id)) => data.insert_temp(shown, *id), + None => data.remove_temp::(shown), + }); + hosted.map(|(output, _)| output) +} + +fn host_editor(app: &mut crate::SlideApp, ui: &mut Ui, space: &CanvasSpace, before: Option) -> Option<(TextEditorOutput, egui::Id)> { if crate::dialogs::modal_open(ui.ctx()) || app.palette_open || app.backstage_open() { - eprintln!("DIAG korean_composes_in_a_slide_text_box: blocked modal={} palette={} backstage={}", crate::dialogs::modal_open(ui.ctx()), app.palette_open, app.backstage_open()); return None; } let state = app.session.active()?; - let Some(target) = state.selection.text.as_ref().filter(|target| !target.notes).cloned() else { - eprintln!("DIAG korean_composes_in_a_slide_text_box: no text target"); - return None; - }; + let target = state.selection.text.as_ref().filter(|target| !target.notes).cloned()?; let id = ui.make_persistent_id(("slide-text-editor", state.uid, target.shape, target.cell)); if focus::focused_rec(ui.ctx()) .is_some_and(|record| record.stop.id != id && record.stop.text && !record.stop.keys.is_document_editor()) { - eprintln!("DIAG korean_composes_in_a_slide_text_box: another text stop owns focus"); return None; } if let Err(error) = app.session.begin_text_edit_session() { @@ -330,12 +340,10 @@ pub(crate) fn show_editor(app: &mut crate::SlideApp, ui: &mut Ui, space: &Canvas return None; } let mut host = EngineTextHost::new(&mut app.session, target); - let Some(bounds) = host.bounds(space) else { - eprintln!("DIAG korean_composes_in_a_slide_text_box: no bounds, frame={}", host.frame.is_some()); - return None; - }; + let bounds = host.bounds(space)?; let mut selection = host.offsets.selection(&host.target); let editor = TextEditor::new("Text", &mut host, Bind::bound(&mut selection)).id(id).click_runs(ClickRuns::Paragraphs); + let editor = if before == Some(id) { editor } else { editor.request_focus(FocusRequest::Take) }; let output = if app.caret_blink == Some(false) { with_env(ui, |env| env.motion = Some(MotionMode::Off), |ui| editor.show_at(ui, bounds)) } else { @@ -356,5 +364,5 @@ pub(crate) fn show_editor(app: &mut crate::SlideApp, ui: &mut Ui, space: &Canvas Err(error) => app.set_status(error.to_string()), } } - Some(output) + Some((output, id)) } diff --git a/crates/ui-egui/src/panels/pattern_fill_tests.rs b/crates/ui-egui/src/panels/pattern_fill_tests.rs index 08e583bfa..cc8970c97 100644 --- a/crates/ui-egui/src/panels/pattern_fill_tests.rs +++ b/crates/ui-egui/src/panels/pattern_fill_tests.rs @@ -46,7 +46,14 @@ fn background_pattern(h: &Harness<'_, SlideApp>) -> PatternFill { /// Enter a colour through the menu's named hex field and submit it with Enter. fn pick_hex(h: &mut Harness<'_, SlideApp>, button: &str, hex: &str) { - h.get_by_role_and_label(Role::Button, button).click(); + // The opener is hovered before it is pressed, as a pointer reaches it. + let opener = h.get_by_role_and_label(Role::Button, button).rect().center(); + h.input_mut().events.push(Event::PointerMoved(opener)); + h.run_steps(2); + for pressed in [true, false] { + h.input_mut().events.push(Event::PointerButton { pos: opener, button: egui::PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); + h.run_steps(2); + } h.run_steps(2); h.get_by_role_and_label(Role::TextInput, "More Colors…").click(); h.run_steps(1); diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 1fe692c16..4d5ecd53a 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -231,7 +231,8 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) { let action = if pick.remove { "remove" } else { "add" }; let _ = qat::command(app, &json!({action: pick.id, "params": pick.params, "label": pick.label, "icon": pick.icon})); } - if let Some(key) = output.picked { + // A click on a tab comes back as the shown tab; `picked` is the overflow menu's choice. + if let Some(key) = output.picked.or(output.shown) { match key { TabKey::File => app.open_backstage(crate::backstage::Page::Home), TabKey::Tab(id) => app.ui.tab = id.into(), diff --git a/crates/ui-egui/src/ribbon/states.rs b/crates/ui-egui/src/ribbon/states.rs index 1e1de54b3..8df131932 100644 --- a/crates/ui-egui/src/ribbon/states.rs +++ b/crates/ui-egui/src/ribbon/states.rs @@ -122,9 +122,6 @@ mod tests { ); h.get_by_role_and_label(Role::Tab, "View").click(); h.run_steps(3); - for node in h.query_all_by_role(Role::Button).chain(h.query_all_by_role(Role::CheckBox)) { - eprintln!("DIAG a_toggle_shows_checked_while_the_state_it_changes_holds: {:?} {:?}", node.accesskit_node().role(), node.accesskit_node().label()); - } let off = h.get_by_role_and_label(Role::Button, "Slide Master").accesskit_node().toggled(); assert_eq!(off, Some(Toggled::False)); h.get_by_role_and_label(Role::Button, "Slide Master").click(); diff --git a/crates/ui-egui/src/sorter/ui_tests.rs b/crates/ui-egui/src/sorter/ui_tests.rs index b7345d003..de849c294 100644 --- a/crates/ui-egui/src/sorter/ui_tests.rs +++ b/crates/ui-egui/src/sorter/ui_tests.rs @@ -279,9 +279,11 @@ fn the_outline_view_leaves_footer_date_and_slide_number_out() { h.state_mut().ui.view = crate::ViewMode::Outline; h.run_steps(3); let words = craft::ui::runtime::env::Env::of_root(&h.ctx).words::(); - let values: Vec<_> = h.query_all_by_role(Role::TextInput).filter_map(|node| node.value()).collect(); + let values: Vec<_> = + h.query_all_by_role(Role::TextInput).chain(h.query_all_by_role(Role::MultilineTextInput)).filter_map(|node| node.value()).collect(); assert!(h.query_all_by_role_and_label(Role::TextInput, words.slide_title.as_str()).next().is_some()); - assert!(h.query_all_by_role_and_label(Role::TextInput, words.slide_text.as_str()).next().is_some()); + // The body is a multi-line field, which the framework exposes with its own role. + assert!(h.query_all_by_role_and_label(Role::MultilineTextInput, words.slide_text.as_str()).next().is_some()); for text in included { assert!(values.contains(&text), "title and body belong in the Outline"); }