08cdea58d7
Tabs: no cap (a 5000 bound on the saved list only); only the active and 5 recent tabs keep editor state, cold tabs keep caret, view and folds and reload on activation, dirty tabs are never dropped; the strip lays out at most 64 tabs and the overflow list is searchable and virtualised; restore loads only the active tab. Hotkeys: one registry with defaults for tab and panel navigation and opening Outline, Related, Backlinks, Assistant, Lint and Comments, shown in the tooltips; F6 cycles focus; Ctrl+h/l in vim mode; panels are accessibility landmarks. Menus: keycap letters that run the item, vim j/k/h/l/gg/G, focus into the menu and back on Esc, menu and menu-item roles. Explorer: horizontal scroll (Shift+wheel) and full-name tooltips. Comments tab in the right panel (MiniMax M3.1 Flash). Delete confirmation dialog from an earlier session, with its debug code and deadlock removed. Built by Claude Sonnet and MiniMax M3.1 Flash; the whole tree verified with cargo xtask ci (fmt, clippy -D warnings, all tests, layers, tree, i18n) green on a copy of the working tree. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
231 lines
9.7 KiB
Rust
231 lines
9.7 KiB
Rust
//! End-to-end headless shell resizing, collapse controls and persisted preferences.
|
|
|
|
use egui::{Context, Event, Id, Key, Modifiers, PointerButton, Pos2, RawInput, Rect, vec2};
|
|
use notescraft_ui_egui::{
|
|
app::NotesApp,
|
|
layout::LayoutRects,
|
|
right_view::RightTab,
|
|
sidebar_tabs::SidebarTab,
|
|
sounds::{Cue, SoundSink},
|
|
tabs::SETTINGS_PATH,
|
|
};
|
|
use std::{cell::RefCell, rc::Rc};
|
|
|
|
struct Harness {
|
|
ctx: Context,
|
|
app: NotesApp,
|
|
time: f64,
|
|
}
|
|
|
|
impl Harness {
|
|
fn new(name: &str) -> Option<Self> {
|
|
let path = std::env::temp_dir().join(format!("notescraft-resize-{name}-{}", std::process::id()));
|
|
assert!(std::fs::create_dir_all(&path).is_ok());
|
|
assert!(std::fs::write(path.join("note.md"), "# Heading\n\nExample note.\n").is_ok());
|
|
let mut session = notescraft_engine::Session::open(&path).ok()?;
|
|
session.use_settings_dir(path.join("config"));
|
|
let mut app = NotesApp::new(session, notescraft_themes::builtin("catppuccin-mocha")?);
|
|
app.state.animations = false;
|
|
app.open_note("note.md");
|
|
let mut harness = Self { ctx: Context::default(), app, time: 0.0 };
|
|
for _ in 0..4 {
|
|
harness.frame(1440.0, Vec::new());
|
|
}
|
|
Some(harness)
|
|
}
|
|
|
|
fn frame(&mut self, width: f32, events: Vec<Event>) -> Vec<String> {
|
|
self.time += 1.0 / 60.0;
|
|
let input = RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(width, 900.0))), time: Some(self.time), events, ..RawInput::default() };
|
|
let mut out = self.ctx.run_ui(input, |ui| self.app.ui(ui.ctx()));
|
|
let labels = out
|
|
.shapes
|
|
.iter()
|
|
.filter_map(|shape| match &shape.shape {
|
|
egui::epaint::Shape::Text(text) => Some(text.galley.text().to_owned()),
|
|
_ => None,
|
|
})
|
|
.collect();
|
|
out.textures_delta.clear();
|
|
labels
|
|
}
|
|
|
|
fn rects(&self) -> LayoutRects {
|
|
let rects = self.ctx.data(|data| data.get_temp::<LayoutRects>(Id::new("card-frame")));
|
|
assert!(rects.is_some());
|
|
rects.unwrap_or(LayoutRects { sidebar: None, editor: None, right: None })
|
|
}
|
|
|
|
fn click(&mut self, pos: Pos2) {
|
|
self.click_in(1440.0, pos);
|
|
}
|
|
|
|
fn click_in(&mut self, width: f32, pos: Pos2) {
|
|
self.frame(width, pointer(pos, true));
|
|
self.frame(width, pointer(pos, false));
|
|
self.frame(width, Vec::new());
|
|
}
|
|
}
|
|
|
|
/// The clearance at the top of the left card for the macOS traffic lights.
|
|
const TOP: f32 = notescraft_ui_egui::titlebar::TRAFFIC_LIGHT_CLEARANCE;
|
|
|
|
fn pointer(pos: Pos2, pressed: bool) -> Vec<Event> {
|
|
vec![Event::PointerMoved(pos), Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }]
|
|
}
|
|
|
|
fn key(alt: bool) -> Vec<Event> {
|
|
// Cmd+B toggles the sidebar and Cmd+Alt+\ the right panel (Cmd+Alt+B is the editor's block menu).
|
|
let key = if alt { Key::Backslash } else { Key::B };
|
|
vec![Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers { command: true, alt, ..Modifiers::NONE } }]
|
|
}
|
|
|
|
#[test]
|
|
fn collapse_buttons_grow_editor_and_rail_tabs_expand_and_select() {
|
|
let harness = Harness::new("buttons");
|
|
assert!(harness.is_some());
|
|
let Some(mut harness) = harness else { return };
|
|
let before = harness.rects().editor.map(|rect| rect.width());
|
|
harness.click(egui::pos2(278.0, 38.0 + TOP));
|
|
assert!(!harness.app.state.sidebar_visible);
|
|
assert!(harness.rects().editor.map(|rect| rect.width()) > before);
|
|
harness.click(egui::pos2(22.0, 74.0 + TOP));
|
|
assert!(harness.app.state.sidebar_visible);
|
|
assert_eq!(harness.app.state.sidebar_tab, SidebarTab::Explorer);
|
|
harness.frame(1440.0, key(false));
|
|
harness.frame(1440.0, Vec::new());
|
|
harness.click(egui::pos2(22.0, 110.0 + TOP));
|
|
assert!(harness.app.state.sidebar_visible);
|
|
assert_eq!(harness.app.state.sidebar_tab, SidebarTab::Search);
|
|
harness.click(egui::pos2(1402.0, 38.0));
|
|
assert!(!harness.app.state.right_visible);
|
|
// The rail reads Backlinks, Related, Lint, Outline, Assistant: the fourth slot is Outline.
|
|
harness.click(egui::pos2(1418.0, 182.0));
|
|
assert!(harness.app.state.right_visible);
|
|
assert_eq!(harness.app.right_tab, RightTab::Outline);
|
|
}
|
|
|
|
#[test]
|
|
fn shell_drag_is_live_and_preserves_centre_budget() {
|
|
let harness = Harness::new("drag");
|
|
assert!(harness.is_some());
|
|
let Some(mut harness) = harness else { return };
|
|
let start = egui::pos2(312.0, 400.0);
|
|
harness.frame(1440.0, pointer(start, true));
|
|
harness.frame(1440.0, vec![Event::PointerMoved(start + vec2(40.0, 0.0))]);
|
|
assert_eq!(harness.app.state.sidebar_width, 340.0);
|
|
assert_eq!(harness.rects().sidebar.map(|rect| rect.width()), Some(340.0));
|
|
harness.frame(1440.0, vec![Event::PointerMoved(start + vec2(900.0, 0.0))]);
|
|
assert_eq!(harness.app.state.sidebar_width, 520.0);
|
|
assert!(harness.rects().editor.is_some_and(|rect| rect.width() >= 360.0));
|
|
harness.frame(1440.0, vec![Event::PointerMoved(start - vec2(200.0, 0.0))]);
|
|
assert!(!harness.app.state.sidebar_visible);
|
|
}
|
|
|
|
#[test]
|
|
fn reset_remembers_default_even_when_window_limits_displayed_width() {
|
|
let harness = Harness::new("reset-budget");
|
|
assert!(harness.is_some());
|
|
let Some(mut harness) = harness else { return };
|
|
harness.app.state.sidebar_width = 520.0;
|
|
harness.app.state.right_width = 560.0;
|
|
harness.frame(900.0, Vec::new());
|
|
harness.frame(900.0, Vec::new());
|
|
for _ in 0..2 {
|
|
harness.click_in(900.0, egui::pos2(281.0, 400.0));
|
|
}
|
|
assert_eq!(harness.app.state.sidebar_width, 300.0);
|
|
assert!(harness.rects().editor.is_some_and(|rect| rect.width() >= 360.0));
|
|
}
|
|
|
|
#[test]
|
|
fn narrow_window_restores_automatic_choices_and_settings_preserve_choices() {
|
|
let harness = Harness::new("narrow");
|
|
assert!(harness.is_some());
|
|
let Some(mut harness) = harness else { return };
|
|
// 620 pt: still narrow enough for both automatic rails, but above the compact (phone) band below 600 pt.
|
|
harness.frame(620.0, Vec::new());
|
|
assert_eq!(harness.rects().sidebar.map(|rect| rect.width()), Some(notescraft_ui_egui::panel_resize::RAIL_WIDTH));
|
|
assert_eq!(harness.rects().right.map(|rect| rect.width()), Some(notescraft_ui_egui::panel_resize::RAIL_WIDTH));
|
|
assert!(harness.app.state.sidebar_visible && harness.app.state.right_visible);
|
|
harness.frame(1440.0, Vec::new());
|
|
assert_eq!(harness.rects().sidebar.map(|rect| rect.width()), Some(300.0));
|
|
harness.frame(1440.0, key(false));
|
|
harness.app.open_note(SETTINGS_PATH);
|
|
harness.frame(1440.0, Vec::new());
|
|
assert!(!harness.app.state.sidebar_visible && harness.app.state.right_visible);
|
|
harness.app.open_note("note.md");
|
|
harness.frame(1440.0, Vec::new());
|
|
assert_eq!(harness.rects().sidebar.map(|rect| rect.width()), Some(notescraft_ui_egui::panel_resize::RAIL_WIDTH));
|
|
assert_eq!(harness.rects().right.map(|rect| rect.width()), Some(300.0));
|
|
}
|
|
|
|
#[test]
|
|
fn panel_widths_and_collapse_choices_survive_restart() {
|
|
let harness = Harness::new("restart");
|
|
assert!(harness.is_some());
|
|
let Some(mut harness) = harness else { return };
|
|
harness.app.state.sidebar_width = 340.0;
|
|
harness.app.state.right_width = 420.0;
|
|
harness.app.state.sidebar_visible = false;
|
|
harness.app.state.right_visible = false;
|
|
harness.app.persist_ui();
|
|
let root = harness.app.session.vault().root().to_path_buf();
|
|
drop(harness);
|
|
let session = notescraft_engine::Session::open(&root);
|
|
assert!(session.is_ok());
|
|
let Ok(mut session) = session else { return };
|
|
session.use_settings_dir(root.join("config"));
|
|
let theme = notescraft_themes::builtin("catppuccin-mocha");
|
|
assert!(theme.is_some());
|
|
let Some(theme) = theme else { return };
|
|
let app = NotesApp::new(session, theme);
|
|
assert_eq!(app.state.sidebar_width, 340.0);
|
|
assert_eq!(app.state.right_width, 420.0);
|
|
assert!(!app.state.sidebar_visible && !app.state.right_visible);
|
|
}
|
|
|
|
struct Sink(Rc<RefCell<Vec<Cue>>>);
|
|
impl SoundSink for Sink {
|
|
fn play(&mut self, cue: Cue, _: f32) {
|
|
self.0.borrow_mut().push(cue);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn shortcuts_and_palette_changes_emit_collapse_and_expand_cues() {
|
|
let harness = Harness::new("cues");
|
|
assert!(harness.is_some());
|
|
let Some(mut harness) = harness else { return };
|
|
let cues = Rc::new(RefCell::new(Vec::new()));
|
|
harness.app.set_sound_sink(Box::new(Sink(cues.clone())));
|
|
harness.frame(1440.0, key(true));
|
|
assert!(!harness.app.state.right_visible);
|
|
assert_eq!(*cues.borrow(), [Cue::Close]);
|
|
harness.app.run_command("ui.toggle_right_panel", &serde_json::Value::Null);
|
|
harness.frame(1440.0, Vec::new());
|
|
assert_eq!(*cues.borrow(), [Cue::Close, Cue::Pop]);
|
|
}
|
|
|
|
#[test]
|
|
fn collapse_animates_and_hidden_content_is_not_squashed() {
|
|
let harness = Harness::new("animations");
|
|
assert!(harness.is_some());
|
|
let Some(mut harness) = harness else { return };
|
|
harness.app.state.animations = true;
|
|
harness.frame(1440.0, Vec::new());
|
|
harness.app.run_command("ui.toggle_right_panel", &serde_json::Value::Null);
|
|
harness.frame(1440.0, Vec::new());
|
|
assert!(harness.rects().right.is_some_and(|rect| rect.width() > notescraft_ui_egui::panel_resize::RAIL_WIDTH && rect.width() < 300.0));
|
|
for _ in 0..120 {
|
|
let labels = harness.frame(1440.0, Vec::new());
|
|
if harness.rects().right.is_some_and(|rect| rect.width() < 120.0) {
|
|
assert!(!labels.iter().any(|label| label == "Backlinks" || label == "Outline"));
|
|
}
|
|
}
|
|
assert_eq!(harness.rects().right.map(|rect| rect.width()), Some(notescraft_ui_egui::panel_resize::RAIL_WIDTH));
|
|
harness.app.state.animations = false;
|
|
harness.frame(1440.0, key(true));
|
|
assert_eq!(harness.rects().right.map(|rect| rect.width()), Some(300.0));
|
|
}
|