Skip to content

Commit 3610cd6

Browse files
committed
Thumbnails: navigating slides scrolls the pane to keep the current slide visible (#917)
The pane scrolled only by hand: past a screenful of slides, arrow-key navigation left the current thumbnail out of view. When the slide changes, the pane now scrolls it into view - minimally, only once the thumbnail has left the viewport, as in PowerPoint, so a visible thumbnail never moves the pane and the user's own scrolling stands. The pane's scroll offset is recorded in UiState (skipped by serde) for the control channel and tests.
1 parent f34f412 commit 3610cd6

3 files changed

Lines changed: 76 additions & 1 deletion

File tree

‎ROADMAP.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ app's JSON control channel (`deckcraft --control PORT`).
137137
| 2026-10-17 | Edit Points: turning a shape into a freeform is one undo step, so Undo brings the original shape back (it used to stay a freeform) |
138138
| 2026-10-17 | While a placeholder's text is being edited, a click on a shape in front of it selects that shape instead of moving the caret, as in PowerPoint (#931) |
139139
| 2026-10-15 | Native saves keep an imported chart's embedded workbook, drawings and relationships; headless PPTX → edit → native save/reopen → PPTX tests verify the payloads and stale-workbook rejection |
140+
| 2026-10-18 | Thumbnails: navigating slides with the arrow keys scrolls the thumbnail pane to keep the current slide visible (#917) |
140141
| 2026-10-15 | PPTX trigger sequences keep separate On Click steps, including paragraph builds; synthetic import/edit/save/reopen and headless show regressions |
141142
| 2026-10-16 | Export: PNG with a transparent background — the slide background is left out, only the slide's content is drawn (Export… dialog, File › Export, web download, `file.export`/`file.render` `transparentBackground`, `deckcraft-cli render --transparent`) (#784) |
142143
| 2026-10-16 | Arrange ▸ Align: Align to Slide and Align Selected Objects, as in PowerPoint. One object aligns to the slide and several to each other until the other choice is ticked; the choice holds for that selection and also drives Distribute |

‎crates/ui-egui/src/lib.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ pub struct UiState {
244244
pub notes: bool,
245245
pub notes_height: f32,
246246
pub thumbs_width: f32,
247+
/// Vertical scroll offset of the thumbnail pane, recorded each frame for the control
248+
/// channel and tests; not persisted.
249+
#[serde(skip)]
250+
pub thumbs_scroll: f32,
247251
/// Open task pane: `format`, `animation`, `selection`, `comments`, `designer`, `background`,
248252
/// `smartart` (Text Pane).
249253
pub pane: Option<String>,
@@ -286,6 +290,7 @@ impl Default for UiState {
286290
notes: true,
287291
notes_height: 52.0,
288292
thumbs_width: 236.0,
293+
thumbs_scroll: 0.0,
289294
pane: None,
290295
pane_width: 300.0,
291296
ruler: false,

‎crates/ui-egui/src/thumbs.rs‎

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) {
2626
master_list(app, ui);
2727
return;
2828
}
29-
egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
29+
let out = egui::ScrollArea::vertical().auto_shrink([false, false]).show(ui, |ui| {
3030
ui.add_space(8.0);
3131
list(app, ui);
3232
ui.add_space(20.0);
3333
});
34+
// Where the pane is scrolled to, for the control channel and tests (#917).
35+
app.ui.thumbs_scroll = out.state.offset.y;
3436
});
3537
// Focus follows the last press: inside the pane keeps it, anywhere else (canvas, ribbon) drops it.
3638
if let Some(pos) = ui.input(|i| if i.pointer.primary_pressed() { i.pointer.interact_pos() } else { None }) {
@@ -47,6 +49,16 @@ fn list(app: &mut SlideApp, ui: &mut Ui) {
4749
let width = ui.available_width();
4850
let tw = (width - 40.0).max(60.0);
4951
let th = tw * (doc.slide_size.height / doc.slide_size.width.max(1.0)) as f32;
52+
// Scroll the current slide into view when it changes, so arrow-key navigation follows
53+
// along in the pane (#917). The scroll itself is minimal, only when the thumbnail leaves
54+
// the view, as in PowerPoint, so the user's own scrolling stands; the first frame only
55+
// records the slide.
56+
let scroll_key = ui.id().with("thumb_scrolled_to");
57+
let slide_changed = ui.data_mut(|d| {
58+
let last: Option<usize> = d.get_temp(scroll_key);
59+
d.insert_temp(scroll_key, cur);
60+
last.is_some_and(|last| last != cur)
61+
});
5062
let ppp = ui.ctx().pixels_per_point();
5163
let mut budget = 3u32;
5264
let mut rects = vec![];
@@ -166,6 +178,10 @@ fn list(app: &mut SlideApp, ui: &mut Ui) {
166178
if need_more {
167179
ui.ctx().request_repaint();
168180
}
181+
// Scroll the current slide's thumbnail into view when the slide changes (#917).
182+
if slide_changed && let Some((_, row_rect)) = rects.iter().find(|(i, _)| *i == cur) {
183+
ui.scroll_to_rect(*row_rect, None);
184+
}
169185
// Drag reorder: insertion line.
170186
if let Some((from, _)) = app.thumb_drag {
171187
if let Some(pp) = ui.input(|i| i.pointer.interact_pos()) {
@@ -323,3 +339,56 @@ fn master_list(app: &mut SlideApp, ui: &mut Ui) {
323339
}
324340
});
325341
}
342+
343+
#[cfg(test)]
344+
mod tests {
345+
use egui_kittest::Harness;
346+
347+
use super::*;
348+
use crate::Services;
349+
use deckcraft_engine::Session;
350+
351+
fn harness() -> Harness<'static, SlideApp> {
352+
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_ui_state(
353+
|ui, app: &mut SlideApp| {
354+
app.logic(ui.ctx());
355+
app.ui(ui);
356+
},
357+
SlideApp::new(Session::with_new(), Services::default()),
358+
);
359+
h.run_steps(3);
360+
h
361+
}
362+
363+
/// Vertical scroll offset of the thumbnail pane, as recorded each frame by `show`.
364+
fn thumbs_scroll(h: &Harness<'_, SlideApp>) -> f32 {
365+
h.state().ui.thumbs_scroll
366+
}
367+
368+
/// #917: navigating to a slide below the fold scrolls the pane to reveal it; a neighbour
369+
/// that is already on screen does not move the pane.
370+
#[test]
371+
fn navigating_slides_keeps_the_current_thumbnail_visible() {
372+
let mut h = harness();
373+
for _ in 0..30 {
374+
h.state_mut().session.execute("slide.new", &json!({})).unwrap();
375+
}
376+
// slide.new selects each new slide; back to the first so the pane starts at the top.
377+
h.state_mut().session.execute("slide.go", &json!({"index": 0})).unwrap();
378+
h.run_steps(3);
379+
let last = h.state().session.active().unwrap().doc.slides.len() - 1;
380+
assert_eq!(thumbs_scroll(&h), 0.0, "the pane starts at the top");
381+
382+
// Jump to the last slide: the pane follows and reveals it.
383+
h.state_mut().session.execute("slide.go", &json!({"index": last})).unwrap();
384+
h.run_steps(120); // the scroll eases in over several frames
385+
let jumped = thumbs_scroll(&h);
386+
assert!(jumped > 100.0, "the pane scrolled to the last slide, offset {jumped}");
387+
388+
// One slide up was already on screen after that scroll: the pane holds still.
389+
h.state_mut().session.execute("slide.go", &json!({"index": last - 1})).unwrap();
390+
h.run_steps(120);
391+
let held = thumbs_scroll(&h);
392+
assert!((held - jumped).abs() < 1.0, "no re-scroll for a visible slide: {jumped} -> {held}");
393+
}
394+
}

0 commit comments

Comments
 (0)