documents and editor: a writing view - measure, font, scale, focus fading, typewriter centering
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e89fb32f43
commit
508fee9d15
13 files changed
+299
-12
No files matched your search
@@ -0,0 +1,108 @@
|
||||
use gpui::{TestAppContext, px, rems};
|
||||
|
||||
use super::{MarkdownMode, frames, open};
|
||||
use crate::documents::DocumentLook;
|
||||
|
||||
/// Sixty short paragraphs, each its own block.
|
||||
fn long() -> String {
|
||||
(0..60).map(|n| format!("Paragraph {n}.\n\n")).collect()
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_measure_narrows_the_column(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open("A paragraph.\n", MarkdownMode::Visual, cx);
|
||||
let look = DocumentLook {
|
||||
measure: Some(rems(20.)),
|
||||
..DocumentLook::default()
|
||||
};
|
||||
document.update(cx, |document, cx| document.set_look(look, cx));
|
||||
frames(cx);
|
||||
let block = cx.debug_bounds("markdown-block-0").expect("drawn");
|
||||
assert!(block.size.width <= px(320.0), "{:?}", block.size);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn typewriter_keeps_the_open_block_mid_view(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open(&long(), MarkdownMode::Visual, cx);
|
||||
let look = DocumentLook {
|
||||
typewriter: true,
|
||||
..DocumentLook::default()
|
||||
};
|
||||
document.update_in(cx, |document, window, cx| {
|
||||
document.set_look(look, cx);
|
||||
document.open(Some(40), false, window, cx);
|
||||
document.list.scroll_to_reveal_item(40);
|
||||
});
|
||||
frames(cx);
|
||||
let (block, view) = document.read_with(cx, |document, _| {
|
||||
(
|
||||
document.list.bounds_for_item(40),
|
||||
document.list.viewport_bounds(),
|
||||
)
|
||||
});
|
||||
let block = block.expect("block 40 is laid out");
|
||||
let off = (block.center().y - view.center().y).abs();
|
||||
assert!(off < px(4.0), "{off:?} from the middle");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn typewriter_keeps_the_source_caret_mid_view(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open(&long(), MarkdownMode::Source, cx);
|
||||
let look = DocumentLook {
|
||||
typewriter: true,
|
||||
..DocumentLook::default()
|
||||
};
|
||||
document.update(cx, |document, cx| {
|
||||
document.set_look(look, cx);
|
||||
document.set_caret(90, 0, cx);
|
||||
});
|
||||
frames(cx);
|
||||
let before = document.read_with(cx, |document, cx| document.top_line(cx));
|
||||
let editor = document.read_with(cx, |document, _| document.editor().clone());
|
||||
let focus = editor.read_with(cx, gpui::Focusable::focus_handle);
|
||||
cx.update(|window, cx| window.focus(&focus, cx));
|
||||
cx.simulate_input(
|
||||
"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
",
|
||||
);
|
||||
frames(cx);
|
||||
let after = document.read_with(cx, |document, cx| document.top_line(cx));
|
||||
assert_eq!(after, before + 10, "the view follows the caret");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_scale_sizes_source_lines(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open("a\n", MarkdownMode::Source, cx);
|
||||
let editor = document.read_with(cx, |document, _| document.editor().clone());
|
||||
frames(cx);
|
||||
let plain = editor.read_with(cx, |editor, _| editor.metrics.line);
|
||||
let look = DocumentLook {
|
||||
scale: 2.0,
|
||||
..DocumentLook::default()
|
||||
};
|
||||
document.update(cx, |document, cx| document.set_look(look, cx));
|
||||
frames(cx);
|
||||
let large = editor.read_with(cx, |editor, _| editor.metrics.line);
|
||||
assert!(large > plain * 1.8, "{plain:?} to {large:?}");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn focus_counts_the_open_block_as_the_readers(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open(&long(), MarkdownMode::Visual, cx);
|
||||
document.update_in(cx, |document, window, cx| {
|
||||
document.open(Some(3), false, window, cx)
|
||||
});
|
||||
assert_eq!(
|
||||
document.read_with(cx, |document, cx| document.current_block(cx)),
|
||||
3
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user