Better handling of newlines in editor insert and delete
This commit is contained in:
parent
c5deb38cfe
commit
5cc64c77c1
5 changed files with 117 additions and 42 deletions
|
|
@ -24,6 +24,51 @@ fn editor() -> ViEditor<'static, 'static> {
|
|||
ViEditor::new(editor)
|
||||
}
|
||||
|
||||
fn editor_text(editor: &ViEditor<'static, 'static>) -> String {
|
||||
let mut text = String::new();
|
||||
editor.with_buffer(|buffer| {
|
||||
for line in buffer.lines.iter() {
|
||||
text.push_str(line.text());
|
||||
text.push_str(line.ending().as_str());
|
||||
}
|
||||
});
|
||||
text
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editor_line_endings_preserved() {
|
||||
let mut editor = editor();
|
||||
assert_eq!(editor_text(&editor), "");
|
||||
|
||||
let start = Cursor::new(0, 0);
|
||||
for &text in &[
|
||||
"No newlines",
|
||||
"One Newline\n",
|
||||
"Two\nNewlines\n",
|
||||
"LF\nCRLF\r\nCR\rLFCR\n\rNONE",
|
||||
] {
|
||||
editor.start_change();
|
||||
let end = editor.insert_at(start, text, None);
|
||||
editor.finish_change();
|
||||
assert_eq!(editor_text(&editor), text);
|
||||
|
||||
editor.start_change();
|
||||
editor.delete_range(start, end);
|
||||
editor.finish_change();
|
||||
assert_eq!(editor_text(&editor), "");
|
||||
|
||||
editor.start_change();
|
||||
editor.undo();
|
||||
editor.finish_change();
|
||||
assert_eq!(editor_text(&editor), text);
|
||||
|
||||
editor.start_change();
|
||||
editor.redo();
|
||||
editor.finish_change();
|
||||
assert_eq!(editor_text(&editor), "");
|
||||
}
|
||||
}
|
||||
|
||||
// Tests that inserting into an empty editor correctly sets the editor as modified.
|
||||
#[test]
|
||||
fn insert_in_empty_editor_sets_changed() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue