T21b and T21c round 1 fixes

- a page centers only while it fits the view; a wider one starts in reach
- the reveal runs after the pages' prepaint and keys on the hit itself, so a
  new hit at the same index and a hit current from the first frame come into view
- the chapter list scrolls
- zen takes focus when turned on from outside, so Escape leaves it, and hands
  focus back
- the gallery keeps a page's due date and tags
This commit is contained in:
ZacharyZhang-NY committed 2026-09-26 04:55:58 -04:00
1 parent cc82acbe20
commit 9c9e811534
8 files changed
+196 -42

No files matched your search

+31 -4
View File
@@ -1,8 +1,9 @@
use std::{collections::BTreeMap, rc::Rc};
use gpui::{
AnyElement, App, Bounds, ElementId, FontWeight, InteractiveElement, IntoElement, ParentElement,
RenderOnce, ScrollHandle, SharedString, Styled, Window, canvas, div, fill, prelude::*, size,
AnyElement, App, Bounds, ElementId, FocusHandle, FontWeight, InteractiveElement, IntoElement,
ParentElement, RenderOnce, ScrollHandle, SharedString, Styled, Window, canvas, div, fill,
prelude::*, size,
};
use smallvec::SmallVec;
@@ -271,12 +272,35 @@ impl ParentElement for ZenMode {
}
}
/// Zen's own focus, where focus was before zen took it, and whether zen was on last frame.
struct Quiet {
focus: FocusHandle,
previous: Option<FocusHandle>,
was_on: bool,
}
impl RenderOnce for ZenMode {
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme();
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
let (on, exit) = (self.on, self.on_exit);
let quiet = window.use_keyed_state((self.id.clone(), "quiet"), cx, |_, cx| Quiet {
focus: cx.focus_handle(),
previous: None,
was_on: false,
});
let (focus, was_on) = (quiet.read(cx).focus.clone(), quiet.read(cx).was_on);
if on && !was_on && !focus.contains_focused(window, cx) {
log::info!("zen mode: takes focus, so Escape reaches it");
let previous = window.focused(cx);
window.focus(&focus);
quiet.update(cx, |quiet, _| quiet.previous = previous);
}
if on != was_on {
quiet.update(cx, |quiet, _| quiet.was_on = on);
}
let theme = cx.theme();
div()
.id(self.id.clone())
.track_focus(&focus)
.flex()
.flex_col()
.on_key_down(move |event, window, cx| {
@@ -286,6 +310,9 @@ impl RenderOnce for ZenMode {
{
cx.stop_propagation();
log::info!("zen mode: leaves");
if let Some(previous) = quiet.update(cx, |quiet, _| quiet.previous.take()) {
window.focus(&previous);
}
exit(window, cx);
}
})