Skip to content

Commit

Permalink
Add test for swapping anchor and cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Feb 12, 2025
1 parent a193497 commit 1df24d5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/core_editor/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,31 @@ mod test {
editor.run_edit_command(&EditCommand::Undo);
assert_eq!(editor.get_buffer(), "This \r\n is a test");
}

#[test]
fn test_swap_cursor_and_anchor() {
let mut editor = editor_with("This is some test content");
editor.line_buffer.set_insertion_point(0);
editor.update_selection_anchor(true);

for _ in 0..3 {
editor.run_edit_command(&EditCommand::MoveRight { select: true });
}
assert_eq!(editor.selection_anchor, Some(0));
assert_eq!(editor.insertion_point(), 3);
assert_eq!(editor.get_selection(), Some((0, 4)));

editor.run_edit_command(&EditCommand::SwapCursorAndAnchor);
assert_eq!(editor.selection_anchor, Some(3));
assert_eq!(editor.insertion_point(), 0);
assert_eq!(editor.get_selection(), Some((0, 4)));

editor.run_edit_command(&EditCommand::SwapCursorAndAnchor);
assert_eq!(editor.selection_anchor, Some(0));
assert_eq!(editor.insertion_point(), 3);
assert_eq!(editor.get_selection(), Some((0, 4)));
}

#[cfg(feature = "system_clipboard")]
mod without_system_clipboard {
use super::*;
Expand Down

0 comments on commit 1df24d5

Please sign in to comment.