documents: table moves and tidy read apart; a code press names its text
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
0558f0c890
commit
bcee87c08f
12 files changed
+321
-106
No files matched your search
@@ -277,7 +277,7 @@ fn a_format_lapses_when_the_text_moves(cx: &mut TestAppContext) {
|
||||
}
|
||||
|
||||
/// The refusals a document sends by event.
|
||||
fn refusals(
|
||||
pub(super) fn refusals(
|
||||
document: &Entity<MarkdownDocument>,
|
||||
cx: &mut VisualTestContext,
|
||||
) -> Rc<RefCell<Vec<EditRefusal>>> {
|
||||
|
||||
@@ -72,7 +72,7 @@ pub(super) fn target(at: usize, block: TargetBlock) -> DocumentTarget {
|
||||
link: None,
|
||||
image: None,
|
||||
in_table: false,
|
||||
in_code: false,
|
||||
code: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ fn a_code_press_lands_in_its_code(cx: &mut TestAppContext) {
|
||||
let heard = heard(&document, cx);
|
||||
press_on(0, 0, MouseButton::Right, cx);
|
||||
let expected = DocumentTarget {
|
||||
in_code: true,
|
||||
code: Some("let x = 1;".into()),
|
||||
..target("```rust\n".len(), TargetBlock::Code)
|
||||
};
|
||||
assert_eq!(*heard.borrow(), [expected]);
|
||||
@@ -245,8 +245,9 @@ fn code_presses_land_line_for_line(cx: &mut TestAppContext) {
|
||||
let events = heard(&document, cx);
|
||||
press_lines(1, 1, MouseButton::Right, cx);
|
||||
let at = source.find("eta").unwrap();
|
||||
let eol = if source.contains('\r') { "\r\n" } else { "\n" };
|
||||
let expected = DocumentTarget {
|
||||
in_code: true,
|
||||
code: Some(format!("alpha{eol}beta")),
|
||||
..target(at, TargetBlock::Code)
|
||||
};
|
||||
assert_eq!(*events.borrow(), [expected], "{source:?}");
|
||||
@@ -304,7 +305,7 @@ beta
|
||||
press_lines(2, 0, MouseButton::Right, cx);
|
||||
let at = source.find("pha").unwrap();
|
||||
let expected = DocumentTarget {
|
||||
in_code: true,
|
||||
code: Some("alpha\nbeta".into()),
|
||||
..target(at, TargetBlock::Code)
|
||||
};
|
||||
assert_eq!(*events.borrow(), [expected]);
|
||||
@@ -392,3 +393,22 @@ fn an_html_space_moved_by_a_tag_presses_on_its_word(cx: &mut TestAppContext) {
|
||||
let at = source.find("eta").unwrap();
|
||||
assert_eq!(*events.borrow(), [target(at, TargetBlock::Html)]);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_press_beside_the_code_still_names_it(cx: &mut TestAppContext) {
|
||||
let source = "```\nlet x;\n```\n";
|
||||
let (document, cx) = open(source, MarkdownMode::Visual, cx);
|
||||
let events = heard(&document, cx);
|
||||
let bounds = cx.debug_bounds("markdown-block-0").expect("drawn");
|
||||
press_at(
|
||||
bounds.left() + px(4.0),
|
||||
bounds.top() + px(4.0),
|
||||
MouseButton::Right,
|
||||
cx,
|
||||
);
|
||||
let code = events
|
||||
.borrow()
|
||||
.first()
|
||||
.and_then(|target| target.code.clone());
|
||||
assert_eq!(code.as_deref(), Some("let x;"));
|
||||
}
|
||||
@@ -47,7 +47,11 @@ fn a_table_edit_is_one_undo_step_at_the_caret(cx: &mut TestAppContext) {
|
||||
document.edit_table(crate::documents::TableEdit::RowBelow, cx)
|
||||
});
|
||||
assert_eq!(edited, Ok(()));
|
||||
assert_eq!(text(&document, cx), "| A |\n| --- |\n| 1 |\n| |\n");
|
||||
cx.run_until_parked();
|
||||
assert_eq!(
|
||||
text(&document, cx),
|
||||
"| A |\n| ---- |\n| 1 |\n| |\n"
|
||||
);
|
||||
let editor = document.read_with(cx, |document, _| document.editor().clone());
|
||||
editor.update(cx, |editor, cx| editor.undo(cx));
|
||||
assert_eq!(text(&document, cx), "| A |\n| - |\n| 1 |\n");
|
||||
@@ -61,7 +65,7 @@ fn a_new_table_goes_after_the_caret_line(cx: &mut TestAppContext) {
|
||||
});
|
||||
assert_eq!(
|
||||
text(&document, cx),
|
||||
"Intro\n\n| | | |\n| --- | --- | --- |\n| | | |\n| | | |\n\nNext\n"
|
||||
"Intro\n\n| | | |\n| ---- | ---- | ---- |\n| | | |\n| | | |\n\nNext\n"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -143,7 +147,7 @@ fn preview_takes_no_edits(cx: &mut TestAppContext) {
|
||||
document.insert_table(cx),
|
||||
)
|
||||
});
|
||||
let preview = Err(crate::documents::TableRefusal::Preview);
|
||||
let preview = Err(crate::documents::EditRefusal::Preview);
|
||||
assert_eq!(refused, (false, preview, preview));
|
||||
assert_eq!(text(&document, cx), "| A |\n| - |\n| 1 |\n");
|
||||
}
|
||||
@@ -247,5 +251,58 @@ fn a_table_on_an_indented_blank_line_is_a_table(cx: &mut TestAppContext) {
|
||||
document.edit_table(crate::documents::TableEdit::ColumnRight, cx)
|
||||
});
|
||||
assert_eq!(column, Ok(()), "{}", text(&document, cx));
|
||||
cx.run_until_parked();
|
||||
assert!(text(&document, cx).starts_with("| "));
|
||||
}
|
||||
|
||||
const SMALL: &str = "| A | B |\n| - | - |\n| 1 | 2 |\n";
|
||||
|
||||
#[gpui::test]
|
||||
fn a_table_move_reads_apart_as_one_undo_step(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open(SMALL, MarkdownMode::Source, cx);
|
||||
document.update(cx, |document, cx| document.set_caret(2, 2, cx));
|
||||
let moved = document.update(cx, |document, cx| {
|
||||
document.edit_table(crate::documents::TableEdit::MoveRowUp, cx)
|
||||
});
|
||||
assert_eq!(moved, Ok(()));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(
|
||||
text(&document, cx),
|
||||
"| 1 | 2 |\n| ---- | ---- |\n| A | B |\n"
|
||||
);
|
||||
let editor = document.read_with(cx, |document, _| document.editor().clone());
|
||||
editor.update(cx, |editor, cx| editor.undo(cx));
|
||||
assert_eq!(text(&document, cx), SMALL);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_table_edit_at_an_edge_refuses_by_event(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open(SMALL, MarkdownMode::Source, cx);
|
||||
let heard = super::format::refusals(&document, cx);
|
||||
document.update(cx, |document, cx| document.set_caret(2, 2, cx));
|
||||
document.update(cx, |document, cx| {
|
||||
document
|
||||
.edit_table(crate::documents::TableEdit::MoveRowDown, cx)
|
||||
.expect("taken")
|
||||
});
|
||||
cx.run_until_parked();
|
||||
let edge = crate::documents::EditRefusal::Cells(crate::documents::TableRefusal::Edge);
|
||||
assert_eq!(*heard.borrow(), [edge]);
|
||||
assert_eq!(text(&document, cx), SMALL);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn tidy_in_an_open_table_keeps_it_open(cx: &mut TestAppContext) {
|
||||
let (document, cx) = open(SMALL, MarkdownMode::Visual, cx);
|
||||
press(0, Modifiers::none(), cx);
|
||||
document.update(cx, |document, cx| {
|
||||
document
|
||||
.edit_table(crate::documents::TableEdit::Tidy, cx)
|
||||
.expect("taken")
|
||||
});
|
||||
cx.run_until_parked();
|
||||
assert_eq!(
|
||||
opened(&document, cx),
|
||||
"| A | B |\n| ---- | ---- |\n| 1 | 2 |"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user