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..37a2e2bfe 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; @@ -308,21 +311,23 @@ 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. +/// The editor takes keyboard focus in the first pass it is shown, and again after a pass without it. pub(crate) fn show_editor(app: &mut crate::SlideApp, ui: &mut Ui, space: &CanvasSpace) -> Option { - 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"); + let shown = egui::Id::new("slide-text-editor-shown"); + let hosted = ui.data(|data| data.get_temp::(shown)); + let blocked = crate::dialogs::modal_open(ui.ctx()) || app.palette_open || app.backstage_open(); + let target = app.session.active().and_then(|state| { + let target = state.selection.text.as_ref().filter(|target| !target.notes)?; + Some((state.uid, target.clone())) + }); + let (Some((uid, target)), false) = (target, blocked) else { + ui.data_mut(|data| data.remove_temp::(shown)); return None; }; - let id = ui.make_persistent_id(("slide-text-editor", state.uid, target.shape, target.cell)); + let id = ui.make_persistent_id(("slide-text-editor", 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 +335,13 @@ 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 mut editor = TextEditor::new("Text", &mut host, Bind::bound(&mut selection)).id(id).click_runs(ClickRuns::Paragraphs); + if hosted != Some(id) { + editor = editor.request_focus(FocusRequest::Take); + } + ui.data_mut(|data| data.insert_temp(shown, id)); let output = if app.caret_blink == Some(false) { with_env(ui, |env| env.motion = Some(MotionMode::Off), |ui| editor.show_at(ui, bounds)) } else { diff --git a/crates/ui-egui/src/dialogs/photo_album.rs b/crates/ui-egui/src/dialogs/photo_album.rs index fd914354d..f6a44e098 100644 --- a/crates/ui-egui/src/dialogs/photo_album.rs +++ b/crates/ui-egui/src/dialogs/photo_album.rs @@ -310,7 +310,6 @@ fn append_picture(dialog: &mut HostedParamDialog, name: &str, bytes: &[u8], tota pub(crate) fn each_pass(app: &mut SlideApp, _ctx: &egui::Context, dialog: &mut HostedParamDialog) { let files = app.host.files(); for action in dialog.take_actions() { - eprintln!("DIAG create_inserts_the_album_in_one_step: action {action} pick={:?} can_pick={}", app.dialogs.album_pick, files.can_pick()); if action == "addPictures" && app.dialogs.album_pick.is_none() { if files.can_pick() { app.dialogs.album_pick = Some(files.pick(PickRequest::open_many("picture"))); diff --git a/crates/ui-egui/src/dialogs/preferences.rs b/crates/ui-egui/src/dialogs/preferences.rs index ee6840982..3f3a5a6b0 100644 --- a/crates/ui-egui/src/dialogs/preferences.rs +++ b/crates/ui-egui/src/dialogs/preferences.rs @@ -414,7 +414,6 @@ pub(crate) fn open_autocorrect(app: &mut SlideApp, ctx: &Context, host: &mut Dia /// Applies live settings and restores opening values for every external or window Cancel path. pub(crate) fn pump(app: &mut SlideApp, _ctx: &Context, host: &mut DialogHost) { for action in host.take_actions(dialog_id("preferences")) { - eprintln!("DIAG autocorrect_list_edits_survive_nested_and_preferences_cancel: action {action}"); match app.run("text.autocorrect", action) { Ok(reply) => { if let Some(form) = host.get_mut::().and_then(|dialog| dialog.autocorrect.as_mut()) {