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 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-27 18:33:10 +00:00
co-authored by Claude Opus 5.5
parent 8d162e02d3
commit 032eab33c4
6 changed files with 35 additions and 25 deletions
-5
View File
@@ -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();
+21 -13
View File
@@ -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<TextEditorOutput> {
let shown = egui::Id::new("slide-text-editor-shown");
let before = ui.data(|data| data.get_temp::<egui::Id>(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::<egui::Id>(shown),
});
hosted.map(|(output, _)| output)
}
fn host_editor(app: &mut crate::SlideApp, ui: &mut Ui, space: &CanvasSpace, before: Option<egui::Id>) -> 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))
}
@@ -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);
+2 -1
View File
@@ -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(),
-3
View File
@@ -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();
+4 -2
View File
@@ -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::<super::SorterWords>();
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");
}