Merge look-fix2-views app work

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-29 22:49:09 +00:00
co-authored by Claude Opus 5.5
4 changed files with 102 additions and 29 deletions
+4 -2
View File
@@ -24,7 +24,9 @@ impl SlideApp {
/// Run a command by id (UI commands here, everything else in the engine). Errors show in the
/// status bar and are returned.
pub fn run(&mut self, id: &str, params: Value) -> Result<Value, String> {
let before = self.session.active().map(|d| (d.uid, d.selection.slide));
// The current slide by place and by id: a delete or an undo can put another slide at the same place.
let current = |d: &deckcraft_engine::DocState| (d.uid, d.selection.slide, d.current_slide().map(|slide| slide.id));
let before = self.session.active().map(current);
let r = if is_ui_command(id) {
self.run_ui(id, &params)
} else if id == "file.save" && self.host.files().saves_to_page() && params.get("path").is_none() {
@@ -60,7 +62,7 @@ impl SlideApp {
}
self.drain_requests();
if let Some(d) = self.session.active()
&& before != Some((d.uid, d.selection.slide))
&& before != Some(current(d))
{
self.slide_reveal = d.current_slide().map(|slide| slide.id);
}
+7 -1
View File
@@ -59,7 +59,13 @@ pub(crate) fn body(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) {
let (doc, uid) = (state.doc.clone(), state.uid);
let current = doc.slides.get(state.selection.slide).map(|slide| u64::from(slide.id.0));
// PLAN: plan error: slide.selectSlides cannot round-trip the collection's range anchor.
let mut selection = Selection::new(state.selection.slides.iter().map(|id| u64::from(id.0)).collect(), current, current);
// No selected slides (a new document) selects the current one.
let selected = if state.selection.slides.is_empty() {
current.into_iter().collect()
} else {
state.selection.slides.iter().map(|id| u64::from(id.0)).collect()
};
let mut selection = Selection::new(selected, current, current);
let words = cx.words::<ThumbWords>();
let store = thumb_source::thumbnails(ui.ctx());
let pictures = DeckThumbs::new(doc.clone(), app.ui.grayscale);
+49 -26
View File
@@ -4,21 +4,22 @@ use std::collections::HashSet;
use craft::behavior::{Selection, SelectionModel as _, keyed};
use craft::text::ui::notes::NotesEditor;
use craft::theme::ControlSize;
use craft::ui::buttons::Button;
use craft::ui::contract::{
Bind, BodyCx, CollectionEvent, Lazy, Pad, Props as _, ReorderRule, Scroll, Show as _, ShowCollection as _, ShowContainer as _, Sizing,
WordSetCx as _,
};
use craft::ui::display::{Picture, Text};
use craft::ui::display::{Picture, Shade, Text};
use craft::ui::layout_components::{Row, Stack};
use craft::ui::list::ThumbAspect;
use craft::ui::menu::{Menu, MenuItem};
use craft::ui::primitives::{ContentPainterCx, DocRun, DocText, PaintShape, StrokeWidth};
use craft::ui::runtime::commands::{CommandRef, CommandScope, CommandState, Commands as _, EditCommands};
use craft::ui::runtime::env::{Env, Label};
use craft::ui::style::{DataColor, Ink, SurfaceKind};
use craft::ui::style::{DataColor, FieldLook, Ink, SurfaceKind, TypeRole};
use craft::ui::text::TextField;
use craft::ui::tile_grid::{CaptionPlace, GridEvent, GridZoom, GroupHeads, Tile, TileGrid, TileGroup, TileZoom};
use craft::ui::tile_grid::{CaptionPlace, GridEvent, GridZoom, GroupHeads, PictureEdge, Tile, TileGrid, TileGroup, TileZoom};
use deckcraft_model::{Presentation, SlideId};
use egui::{Color32, CornerRadius, Rect, Ui, vec2};
use serde_json::json;
@@ -42,6 +43,7 @@ craft::ui::words! {
transition: template "deckcraft.sorterTransition" = "★ {kind}";
slide_title: plain = "Slide title";
slide_text: plain = "Slide text";
no_title: plain = "This slide has no title placeholder.";
notes: plain = "Notes";
}
}
@@ -94,7 +96,10 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
let (uid, doc, cur) = (st.uid, st.doc.clone(), st.selection.slide);
let lead = doc.slides.get(cur).map(|slide| Key::Slide(slide.id));
let anchor = st.selection.range_anchor.map(|(first, _)| Key::Slide(first)).or(lead);
let mut selection = Selection::new(st.selection.slides.iter().copied().map(Key::Slide).collect(), lead, anchor);
// No selected slides (a new document) selects the current one.
let selected =
if st.selection.slides.is_empty() { lead.into_iter().collect() } else { st.selection.slides.iter().copied().map(Key::Slide).collect() };
let mut selection = Selection::new(selected, lead, anchor);
let mut keys = Vec::with_capacity(doc.slides.len());
let mut heads = Vec::with_capacity(doc.sections.len());
for (section, slides) in groups(&doc) {
@@ -133,6 +138,7 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
.caption(CaptionPlace::Below)
.detail_line()
.groups(&heads)
.picture_edge(PictureEdge::Framed)
.group_heads(GroupHeads::Titled)
.collapsible()
.can_rename_groups()
@@ -344,23 +350,21 @@ pub(crate) fn outline_body(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>)
let _ = Lazy::new(("outline", uid, slide.id.0), 0.0).show(ui, |ui| {
Stack::new().fill_width().show(ui, |ui, _| {
Row::new().fill_width().show(ui, |ui, _| {
Text::new((index + 1).to_string()).show(ui);
Picture::painter(Label::Empty, ThumbAspect::new(4, 3), |cx, rect| {
Text::new((index + 1).to_string()).shade(Shade::Muted).show(ui);
// The slide marker is an outline, in the accent on the current slide.
Picture::painter(Label::Empty, ThumbAspect::new(7, 5), |cx, rect| {
cx.with_draw(|draw| {
let shape = PaintShape::Rect(rect, CornerRadius::ZERO);
if index == current {
draw.fill(&shape, draw.role(|color| color.accent.solid));
} else {
draw.stroke(&shape, StrokeWidth::Thin, draw.role(|color| color.line.frame));
}
let ink = if index == current { draw.role(|color| color.accent.solid) } else { draw.role(|color| color.text.muted) };
draw.stroke(&shape, StrokeWidth::Thin, ink);
});
})
.size(ControlSize::Sm)
.show(ui);
if let Some(title) = title {
let text = title.text.as_ref().map(|text| text.text()).unwrap_or_default();
// PLAN: plan error: TextField has no title type role or weight prop for the Outline title.
outline_field(app, ui, (uid, title.id.0), index, &text, words.slide_title.clone(), false);
}
// A slide without a title placeholder still shows the title field, as every slide's first line.
let text = title.and_then(|title| title.text.as_ref()).map(|text| text.text()).unwrap_or_default();
let field = OutlineLine { key: (uid, slide.id.0), slide: index, shape: title.map(|title| title.id.0), title: true };
outline_field(app, ui, field, &text, &words);
});
Stack::new().indent(2).fill_width().show(ui, |ui, _| {
for shape in &body {
@@ -371,7 +375,8 @@ pub(crate) fn outline_body(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>)
.map(|paragraph| format!("{}{}", "\t".repeat(paragraph.level as usize), paragraph.text()))
.collect::<Vec<_>>()
.join("\n");
outline_field(app, ui, (uid, shape.id.0), index, &text, words.slide_text.clone(), true);
let field = OutlineLine { key: (uid, slide.id.0), slide: index, shape: Some(shape.id.0), title: false };
outline_field(app, ui, field, &text, &words);
}
}
});
@@ -381,18 +386,36 @@ pub(crate) fn outline_body(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>)
});
}
fn outline_field(app: &mut SlideApp, ui: &mut Ui, key: (u64, u32), slide: usize, text: &str, label: Label, multiline: bool) {
let mut field =
TextField::new(label.clone(), Bind::given(text.to_owned())).id_salt(("outline-field", key)).placeholder(label).sizing(Sizing::FillWidth);
if multiline {
field = field.lines(text.lines().count().max(1));
}
let out = field.show(ui);
/// One editable line of the outline: a slide's title or one of its text shapes.
struct OutlineLine {
/// The document and the slide's id.
key: (u64, u32),
slide: usize,
/// The shape the text sets; `None` for the title of a slide without a title placeholder.
shape: Option<u32>,
title: bool,
}
/// Titles are single lines in a larger role than the body text, whose paragraphs wrap at the pane's width. Both are
/// set as running text, with no field box until they take focus.
fn outline_field(app: &mut SlideApp, ui: &mut Ui, line: OutlineLine, text: &str, words: &SorterWords) {
let (title, label) = (line.title, if line.title { words.slide_title.clone() } else { words.slide_text.clone() });
let field = TextField::new(label.clone(), Bind::given(text.to_owned()))
.id_salt(("outline-field", line.key, line.shape, title))
.placeholder(label)
.look(FieldLook::Inline)
.sizing(Sizing::FillWidth);
let out = if title { field.role(TypeRole::BodyLarge) } else { field.wraps() }.show(ui);
if out.response.gained_focus() {
let _ = app.run("slide.go", json!({"index": slide}));
let _ = app.run("slide.go", json!({"index": line.slide}));
}
if let Some(edited) = out.events.committed().filter(|edited| edited.as_str() != text) {
let _ = app.run("text.set", json!({"id": key.1, "text": edited}));
match line.shape {
Some(id) => {
let _ = app.run("text.set", json!({"id": id, "text": edited}));
}
None => app.set_status(words.no_title.as_str().to_owned()),
}
}
}
+42
View File
@@ -291,3 +291,45 @@ fn the_outline_view_leaves_footer_date_and_slide_number_out() {
assert!(!values.contains(&text), "footer, date and slide number stay out of Outline fields");
}
}
/// A command that puts another slide in the current place (a delete, its undo) reveals that slide in the thumbnails
/// pane and the sorter, as a move to another place does, so the pane never keeps an offset with the current slide out
/// of view.
#[test]
fn a_new_current_slide_at_the_same_place_is_revealed() {
let mut h = harness(false);
let current = |h: &Harness<'static, Framed>| h.state().session.active().and_then(|d| d.current_slide().map(|slide| slide.id));
h.state_mut().run("slide.go", json!({"index": 0})).unwrap();
h.state_mut().slide_reveal = None;
h.state_mut().run("slide.delete", json!({})).unwrap();
assert_eq!(h.state().session.active().unwrap().selection.slide, 0, "the next slide takes the deleted one's place");
assert_eq!(h.state_mut().slide_reveal.take(), current(&h), "the slide now at the place is revealed");
h.state_mut().run("edit.undo", json!({})).unwrap();
assert_eq!(h.state_mut().slide_reveal.take(), current(&h), "the slide the undo puts back is revealed");
}
/// Every Outline slide has a title field, also a slide whose layout has no title placeholder, and a long body
/// paragraph wraps over several lines of the pane instead of being cut on one.
#[test]
fn the_outline_gives_every_slide_a_title_field_and_wraps_long_paragraphs() {
let mut s = Session::with_new();
let long = "Aurora forms where charged particles from the sun meet the magnetic field and the upper air. ".repeat(4);
s.execute("slide.new", &json!({"layout": "titleAndContent", "title": "Aurora", "body": long.trim()})).unwrap();
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
let slides = s.active().unwrap().doc.slides.len();
let mut h = crate::test_harness::harness_framed(s, Services::default(), Harness::builder().with_size(egui::vec2(1400.0, 900.0)), |app, ui| {
app.logic(ui.ctx());
crate::panels::show_editor(app, ui);
});
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 titles: Vec<_> = h.query_all_by_role_and_label(Role::TextInput, words.slide_title.as_str()).collect();
assert_eq!(titles.len(), slides, "each slide has its title field, with or without a title placeholder");
let line = titles[0].rect().height();
let body = h
.query_all_by_role_and_label(Role::MultilineTextInput, words.slide_text.as_str())
.find(|node| node.value().is_some_and(|value| value == long.trim()))
.expect("the long body shows in the Outline");
assert!(body.rect().height() > 2.0 * line, "the long paragraph wraps: {} against a title line of {line}", body.rect().height());
}