DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Story Editor: showing or hiding the depth ruler keeps the text's focus
dotCooCoo41b7611b27cb
diff --git a/crates/ui-egui/src/story_editor.rs b/crates/ui-egui/src/story_editor.rsindex ad35b8bcb..189bdb481 100644--- a/crates/ui-egui/src/story_editor.rs+++ b/crates/ui-egui/src/story_editor.rs@@ -67,7 +67,10 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) {// Depth ruler: painted after the text too, beside the rows the lines start on.let ruler = depths.as_ref().map(|_| ui.allocate_exact_size(vec2(RULER_WIDTH, 0.0), egui::Sense::hover()).0);let mut text = story.text.clone();+ // (a fixed id: the ruler's allocation above would otherwise move the editor's auto id,+ // and its focus and caret with it, whenever the ruler is shown or hidden)let out = egui::TextEdit::multiline(&mut text)+ .id_salt("story_text").font(egui::FontId::proportional(app.ui.story_editor_size.clamp(8.0, 36.0))).desired_width(f32::INFINITY).desired_rows(20)@@ -475,6 +478,26 @@ mod tests {}}+ /// Showing or hiding the depth ruler keeps the text's focus and caret: typing after the toggle+ /// still reaches the story.+ #[test]+ fn depth_ruler_toggle_keeps_the_text_focused() {+ let mut app = DesignApp::new(designcraft_engine::Session::new(), Default::default());+ app.run("file.new", json!({})).unwrap();+ let r = app.run("frame.create", json!({"rect": [72, 72, 300, 200], "content": "text", "text": "Ruler story", "caret": false})).unwrap();+ app.run("app.storyEditor", json!({"story": r["story"].as_u64().unwrap()})).unwrap();+ let mut h = crate::test_window::open(app, egui::vec2(1440.0, 900.0));+ h.get_by(|n| n.role() == egui::accesskit::Role::MultilineTextInput && n.value().as_deref() == Some("Ruler story")).focus();+ h.run_steps(2);+ for (toggle, typed) in [("!", "Ruler story!"), ("?", "Ruler story!?")] {+ h.state_mut().app.run("view.storyEditorDepthRuler", json!({})).unwrap();+ h.run_steps(2);+ h.event(egui::Event::Text(toggle.into()));+ h.run_steps(2);+ assert_eq!(story_text(&h.state().app, 0), typed);+ }+ }+/// Story ids are counted per document: typing in the editor after switching documents edited/// the other document's story with the same id.#[test]