documents: undo and redo leave a block only past its own history; typing lands after undo empties the document
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
362a0fc9fa
commit
a3d9f089a3
5 files changed
+137
-87
No files matched your search
@@ -22,7 +22,7 @@ pub(super) fn open<'a>(
|
||||
}
|
||||
|
||||
/// Presses block `ix` where it is drawn.
|
||||
fn press(ix: usize, modifiers: Modifiers, cx: &mut VisualTestContext) {
|
||||
pub(super) fn press(ix: usize, modifiers: Modifiers, cx: &mut VisualTestContext) {
|
||||
let bounds = cx
|
||||
.debug_bounds(Box::leak(format!("markdown-block-{ix}").into_boxed_str()))
|
||||
.expect("the block is drawn");
|
||||
@@ -365,6 +365,7 @@ fn a_press_after_a_write_back_waits_for_the_long_read(cx: &mut TestAppContext) {
|
||||
assert_eq!(opened(&document, cx), "B", "once read, B opens whole");
|
||||
}
|
||||
|
||||
mod history;
|
||||
mod place;
|
||||
|
||||
#[gpui::test]
|
||||
@@ -397,78 +398,3 @@ fn a_text_past_the_largest_read_is_never_read(cx: &mut TestAppContext) {
|
||||
});
|
||||
assert_eq!((blocks, outline), (0, 0), "the old read is gone");
|
||||
}
|
||||
|
||||
/// Focus on `document`'s own handle, as an owner gives it.
|
||||
fn focus(document: &Entity<MarkdownDocument>, cx: &mut VisualTestContext) {
|
||||
let handle = document.read_with(cx, |document, cx| {
|
||||
gpui::Focusable::focus_handle(document, cx)
|
||||
});
|
||||
cx.update(|window, cx| window.focus(&handle, cx));
|
||||
cx.run_until_parked();
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn an_empty_visual_document_takes_typing_on_focus(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open("", MarkdownMode::Visual, cx);
|
||||
focus(&document, cx);
|
||||
cx.simulate_input("Hi");
|
||||
assert_eq!(text(&document, cx), "Hi", "typing lands with no press");
|
||||
cx.simulate_keystrokes("escape");
|
||||
cx.run_until_parked();
|
||||
assert_eq!(text(&document, cx), "Hi", "escape keeps it");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn focus_opens_no_block_in_a_written_document(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open(TEXT, MarkdownMode::Visual, cx);
|
||||
focus(&document, cx);
|
||||
cx.simulate_input("x");
|
||||
assert_eq!(text(&document, cx), TEXT);
|
||||
}
|
||||
|
||||
fn mode(document: &Entity<MarkdownDocument>, mode: MarkdownMode, cx: &mut VisualTestContext) {
|
||||
document.update_in(cx, |document, window, cx| {
|
||||
document.set_mode(mode, window, cx)
|
||||
});
|
||||
cx.run_until_parked();
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn preview_and_back_still_take_typing_in_an_empty_document(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open("", MarkdownMode::Visual, cx);
|
||||
focus(&document, cx);
|
||||
cx.simulate_keystrokes("escape");
|
||||
mode(&document, MarkdownMode::Preview, cx);
|
||||
mode(&document, MarkdownMode::Visual, cx);
|
||||
cx.simulate_input("Hi");
|
||||
assert_eq!(text(&document, cx), "Hi");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn undo_in_an_untouched_block_steps_the_document(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open("Seed", MarkdownMode::Source, cx);
|
||||
document.update(cx, |document, cx| document.set_text("", cx));
|
||||
mode(&document, MarkdownMode::Visual, cx);
|
||||
cx.simulate_keystrokes("secondary-z");
|
||||
cx.run_until_parked();
|
||||
assert_eq!(text(&document, cx), "Seed", "the source edit is undone");
|
||||
cx.simulate_keystrokes("secondary-shift-z");
|
||||
cx.run_until_parked();
|
||||
assert_eq!(text(&document, cx), "", "and redone");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn undo_in_a_typed_block_stays_in_the_block(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open("Seed", MarkdownMode::Source, cx);
|
||||
document.update(cx, |document, cx| document.set_text(TEXT, cx));
|
||||
mode(&document, MarkdownMode::Visual, cx);
|
||||
press(1, Modifiers::none(), cx);
|
||||
cx.simulate_input(" x");
|
||||
cx.simulate_keystrokes("secondary-z");
|
||||
cx.run_until_parked();
|
||||
assert_eq!(
|
||||
text(&document, cx),
|
||||
TEXT,
|
||||
"the typing went, not the edit before"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user