2022-04-21 23:14:58 +00:00
|
|
|
mod change;
|
|
|
|
mod delete;
|
2022-05-23 16:23:25 +00:00
|
|
|
mod yank;
|
2022-04-21 23:14:58 +00:00
|
|
|
|
2022-05-20 00:42:30 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2022-04-22 16:43:15 +00:00
|
|
|
use crate::{
|
|
|
|
motion::Motion,
|
2022-10-06 03:19:30 +00:00
|
|
|
object::Object,
|
2022-04-22 16:43:15 +00:00
|
|
|
state::{Mode, Operator},
|
|
|
|
Vim,
|
|
|
|
};
|
2022-04-21 23:14:58 +00:00
|
|
|
use change::init as change_init;
|
2022-04-29 23:14:01 +00:00
|
|
|
use collections::HashSet;
|
2022-05-20 00:42:30 +00:00
|
|
|
use editor::{Autoscroll, Bias, ClipboardSelection, DisplayPoint};
|
2022-04-22 16:43:15 +00:00
|
|
|
use gpui::{actions, MutableAppContext, ViewContext};
|
2022-07-28 21:03:31 +00:00
|
|
|
use language::{AutoindentMode, Point, SelectionGoal};
|
2022-04-22 16:43:15 +00:00
|
|
|
use workspace::Workspace;
|
2022-04-21 23:14:58 +00:00
|
|
|
|
2022-10-06 03:19:30 +00:00
|
|
|
use self::{
|
|
|
|
change::{change_motion, change_object},
|
|
|
|
delete::{delete_motion, delete_object},
|
|
|
|
yank::{yank_motion, yank_object},
|
|
|
|
};
|
2022-04-21 23:14:58 +00:00
|
|
|
|
2022-04-22 16:43:15 +00:00
|
|
|
actions!(
|
|
|
|
vim,
|
|
|
|
[
|
|
|
|
InsertAfter,
|
|
|
|
InsertFirstNonWhitespace,
|
|
|
|
InsertEndOfLine,
|
|
|
|
InsertLineAbove,
|
|
|
|
InsertLineBelow,
|
|
|
|
DeleteLeft,
|
|
|
|
DeleteRight,
|
|
|
|
ChangeToEndOfLine,
|
|
|
|
DeleteToEndOfLine,
|
2022-05-20 00:42:30 +00:00
|
|
|
Paste,
|
|
|
|
Yank,
|
2022-04-22 16:43:15 +00:00
|
|
|
]
|
|
|
|
);
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
pub fn init(cx: &mut MutableAppContext) {
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.add_action(insert_after);
|
|
|
|
cx.add_action(insert_first_non_whitespace);
|
|
|
|
cx.add_action(insert_end_of_line);
|
|
|
|
cx.add_action(insert_line_above);
|
|
|
|
cx.add_action(insert_line_below);
|
|
|
|
cx.add_action(|_: &mut Workspace, _: &DeleteLeft, cx| {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
2022-10-06 03:19:30 +00:00
|
|
|
delete_motion(vim, Motion::Left, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
cx.add_action(|_: &mut Workspace, _: &DeleteRight, cx| {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
2022-10-06 03:19:30 +00:00
|
|
|
delete_motion(vim, Motion::Right, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
cx.add_action(|_: &mut Workspace, _: &ChangeToEndOfLine, cx| {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
2022-10-06 03:19:30 +00:00
|
|
|
change_motion(vim, Motion::EndOfLine, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
})
|
|
|
|
});
|
|
|
|
cx.add_action(|_: &mut Workspace, _: &DeleteToEndOfLine, cx| {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
2022-10-06 03:19:30 +00:00
|
|
|
delete_motion(vim, Motion::EndOfLine, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
})
|
|
|
|
});
|
2022-05-20 00:42:30 +00:00
|
|
|
cx.add_action(paste);
|
2022-04-22 16:43:15 +00:00
|
|
|
|
2022-04-21 23:14:58 +00:00
|
|
|
change_init(cx);
|
|
|
|
}
|
2022-03-28 00:58:28 +00:00
|
|
|
|
2022-04-15 23:00:44 +00:00
|
|
|
pub fn normal_motion(motion: Motion, cx: &mut MutableAppContext) {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
|
|
|
match vim.state.operator_stack.pop() {
|
|
|
|
None => move_cursor(vim, motion, cx),
|
2022-10-06 03:19:30 +00:00
|
|
|
Some(Operator::Change) => change_motion(vim, motion, cx),
|
|
|
|
Some(Operator::Delete) => delete_motion(vim, motion, cx),
|
|
|
|
Some(Operator::Yank) => yank_motion(vim, motion, cx),
|
|
|
|
_ => {
|
|
|
|
// Can't do anything for text objects or namespace operators. Ignoring
|
2022-04-19 18:36:44 +00:00
|
|
|
}
|
2022-04-15 23:00:44 +00:00
|
|
|
}
|
|
|
|
vim.clear_operator(cx);
|
2022-03-28 00:58:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-10-06 03:19:30 +00:00
|
|
|
pub fn normal_object(object: Object, cx: &mut MutableAppContext) {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
|
|
|
match vim.state.operator_stack.pop() {
|
|
|
|
Some(Operator::Object { around }) => match vim.state.operator_stack.pop() {
|
|
|
|
Some(Operator::Change) => change_object(vim, object, around, cx),
|
|
|
|
Some(Operator::Delete) => delete_object(vim, object, around, cx),
|
|
|
|
Some(Operator::Yank) => yank_object(vim, object, around, cx),
|
|
|
|
_ => {
|
|
|
|
// Can't do anything for namespace operators. Ignoring
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
// Can't do anything with change/delete/yank and text objects. Ignoring
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vim.clear_operator(cx);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-15 23:00:44 +00:00
|
|
|
fn move_cursor(vim: &mut Vim, motion: Motion, cx: &mut MutableAppContext) {
|
|
|
|
vim.update_active_editor(cx, |editor, cx| {
|
2022-05-12 21:18:46 +00:00
|
|
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
2022-05-06 04:09:26 +00:00
|
|
|
s.move_cursors_with(|map, cursor, goal| motion.move_point(map, cursor, goal))
|
|
|
|
})
|
2022-03-28 00:58:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-22 16:43:15 +00:00
|
|
|
fn insert_after(_: &mut Workspace, _: &InsertAfter, cx: &mut ViewContext<Workspace>) {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
2022-07-18 20:33:55 +00:00
|
|
|
vim.switch_mode(Mode::Insert, false, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
vim.update_active_editor(cx, |editor, cx| {
|
2022-05-12 21:18:46 +00:00
|
|
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
2022-05-06 04:09:26 +00:00
|
|
|
s.move_cursors_with(|map, cursor, goal| {
|
|
|
|
Motion::Right.move_point(map, cursor, goal)
|
|
|
|
});
|
2022-04-22 16:43:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn insert_first_non_whitespace(
|
|
|
|
_: &mut Workspace,
|
|
|
|
_: &InsertFirstNonWhitespace,
|
|
|
|
cx: &mut ViewContext<Workspace>,
|
|
|
|
) {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
2022-07-18 20:33:55 +00:00
|
|
|
vim.switch_mode(Mode::Insert, false, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
vim.update_active_editor(cx, |editor, cx| {
|
2022-05-12 21:18:46 +00:00
|
|
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
2022-05-06 04:09:26 +00:00
|
|
|
s.move_cursors_with(|map, cursor, goal| {
|
|
|
|
Motion::FirstNonWhitespace.move_point(map, cursor, goal)
|
|
|
|
});
|
2022-04-22 16:43:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn insert_end_of_line(_: &mut Workspace, _: &InsertEndOfLine, cx: &mut ViewContext<Workspace>) {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
2022-07-18 20:33:55 +00:00
|
|
|
vim.switch_mode(Mode::Insert, false, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
vim.update_active_editor(cx, |editor, cx| {
|
2022-05-12 21:18:46 +00:00
|
|
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
2022-05-06 04:09:26 +00:00
|
|
|
s.move_cursors_with(|map, cursor, goal| {
|
|
|
|
Motion::EndOfLine.move_point(map, cursor, goal)
|
|
|
|
});
|
2022-04-22 16:43:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn insert_line_above(_: &mut Workspace, _: &InsertLineAbove, cx: &mut ViewContext<Workspace>) {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
2022-07-18 20:33:55 +00:00
|
|
|
vim.switch_mode(Mode::Insert, false, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
vim.update_active_editor(cx, |editor, cx| {
|
|
|
|
editor.transact(cx, |editor, cx| {
|
2022-05-13 22:49:14 +00:00
|
|
|
let (map, old_selections) = editor.selections.all_display(cx);
|
2022-04-29 23:14:01 +00:00
|
|
|
let selection_start_rows: HashSet<u32> = old_selections
|
|
|
|
.into_iter()
|
|
|
|
.map(|selection| selection.start.row())
|
|
|
|
.collect();
|
|
|
|
let edits = selection_start_rows.into_iter().map(|row| {
|
|
|
|
let (indent, _) = map.line_indent(row);
|
|
|
|
let start_of_line = map
|
|
|
|
.clip_point(DisplayPoint::new(row, 0), Bias::Left)
|
|
|
|
.to_point(&map);
|
|
|
|
let mut new_text = " ".repeat(indent as usize);
|
|
|
|
new_text.push('\n');
|
|
|
|
(start_of_line..start_of_line, new_text)
|
2022-04-22 16:43:15 +00:00
|
|
|
});
|
2022-05-03 17:29:57 +00:00
|
|
|
editor.edit_with_autoindent(edits, cx);
|
2022-05-12 21:18:46 +00:00
|
|
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
2022-05-06 04:09:26 +00:00
|
|
|
s.move_cursors_with(|map, mut cursor, _| {
|
|
|
|
*cursor.row_mut() -= 1;
|
|
|
|
*cursor.column_mut() = map.line_len(cursor.row());
|
|
|
|
(map.clip_point(cursor, Bias::Left), SelectionGoal::None)
|
|
|
|
});
|
2022-04-22 16:43:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-29 23:14:01 +00:00
|
|
|
fn insert_line_below(_: &mut Workspace, _: &InsertLineBelow, cx: &mut ViewContext<Workspace>) {
|
2022-04-22 16:43:15 +00:00
|
|
|
Vim::update(cx, |vim, cx| {
|
2022-07-18 20:33:55 +00:00
|
|
|
vim.switch_mode(Mode::Insert, false, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
vim.update_active_editor(cx, |editor, cx| {
|
|
|
|
editor.transact(cx, |editor, cx| {
|
2022-05-13 22:49:14 +00:00
|
|
|
let (map, old_selections) = editor.selections.all_display(cx);
|
2022-04-29 23:14:01 +00:00
|
|
|
let selection_end_rows: HashSet<u32> = old_selections
|
|
|
|
.into_iter()
|
|
|
|
.map(|selection| selection.end.row())
|
|
|
|
.collect();
|
|
|
|
let edits = selection_end_rows.into_iter().map(|row| {
|
|
|
|
let (indent, _) = map.line_indent(row);
|
|
|
|
let end_of_line = map
|
|
|
|
.clip_point(DisplayPoint::new(row, map.line_len(row)), Bias::Left)
|
|
|
|
.to_point(&map);
|
|
|
|
let mut new_text = "\n".to_string();
|
|
|
|
new_text.push_str(&" ".repeat(indent as usize));
|
|
|
|
(end_of_line..end_of_line, new_text)
|
2022-04-22 16:43:15 +00:00
|
|
|
});
|
2022-05-12 21:18:46 +00:00
|
|
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
2022-05-06 04:09:26 +00:00
|
|
|
s.move_cursors_with(|map, cursor, goal| {
|
|
|
|
Motion::EndOfLine.move_point(map, cursor, goal)
|
|
|
|
});
|
2022-04-22 16:43:15 +00:00
|
|
|
});
|
2022-05-03 17:29:57 +00:00
|
|
|
editor.edit_with_autoindent(edits, cx);
|
2022-04-22 16:43:15 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-20 00:42:30 +00:00
|
|
|
fn paste(_: &mut Workspace, _: &Paste, cx: &mut ViewContext<Workspace>) {
|
|
|
|
Vim::update(cx, |vim, cx| {
|
|
|
|
vim.update_active_editor(cx, |editor, cx| {
|
|
|
|
editor.transact(cx, |editor, cx| {
|
2022-07-08 17:57:02 +00:00
|
|
|
editor.set_clip_at_line_ends(false, cx);
|
2022-05-20 00:42:30 +00:00
|
|
|
if let Some(item) = cx.as_mut().read_from_clipboard() {
|
|
|
|
let mut clipboard_text = Cow::Borrowed(item.text());
|
|
|
|
if let Some(mut clipboard_selections) =
|
|
|
|
item.metadata::<Vec<ClipboardSelection>>()
|
|
|
|
{
|
2022-07-08 17:57:02 +00:00
|
|
|
let (display_map, selections) = editor.selections.all_display(cx);
|
2022-05-20 00:42:30 +00:00
|
|
|
let all_selections_were_entire_line =
|
|
|
|
clipboard_selections.iter().all(|s| s.is_entire_line);
|
|
|
|
if clipboard_selections.len() != selections.len() {
|
|
|
|
let mut newline_separated_text = String::new();
|
|
|
|
let mut clipboard_selections =
|
|
|
|
clipboard_selections.drain(..).peekable();
|
|
|
|
let mut ix = 0;
|
|
|
|
while let Some(clipboard_selection) = clipboard_selections.next() {
|
|
|
|
newline_separated_text
|
|
|
|
.push_str(&clipboard_text[ix..ix + clipboard_selection.len]);
|
|
|
|
ix += clipboard_selection.len;
|
|
|
|
if clipboard_selections.peek().is_some() {
|
|
|
|
newline_separated_text.push('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clipboard_text = Cow::Owned(newline_separated_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut new_selections = Vec::new();
|
|
|
|
editor.buffer().update(cx, |buffer, cx| {
|
|
|
|
let snapshot = buffer.snapshot(cx);
|
|
|
|
let mut start_offset = 0;
|
|
|
|
let mut edits = Vec::new();
|
|
|
|
for (ix, selection) in selections.iter().enumerate() {
|
|
|
|
let to_insert;
|
|
|
|
let linewise;
|
|
|
|
if let Some(clipboard_selection) = clipboard_selections.get(ix) {
|
|
|
|
let end_offset = start_offset + clipboard_selection.len;
|
|
|
|
to_insert = &clipboard_text[start_offset..end_offset];
|
|
|
|
linewise = clipboard_selection.is_entire_line;
|
|
|
|
start_offset = end_offset;
|
|
|
|
} else {
|
|
|
|
to_insert = clipboard_text.as_str();
|
|
|
|
linewise = all_selections_were_entire_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the clipboard text was copied linewise, and the current selection
|
|
|
|
// is empty, then paste the text after this line and move the selection
|
|
|
|
// to the start of the pasted text
|
2022-07-08 17:57:02 +00:00
|
|
|
let insert_at = if linewise {
|
2022-05-20 00:42:30 +00:00
|
|
|
let (point, _) = display_map
|
|
|
|
.next_line_boundary(selection.start.to_point(&display_map));
|
|
|
|
|
|
|
|
if !to_insert.starts_with('\n') {
|
|
|
|
// Add newline before pasted text so that it shows up
|
|
|
|
edits.push((point..point, "\n"));
|
|
|
|
}
|
|
|
|
// Drop selection at the start of the next line
|
|
|
|
let selection_point = Point::new(point.row + 1, 0);
|
2022-08-10 21:39:24 +00:00
|
|
|
new_selections.push(selection.map(|_| selection_point));
|
2022-07-08 17:57:02 +00:00
|
|
|
point
|
2022-05-20 00:42:30 +00:00
|
|
|
} else {
|
2022-07-08 17:57:02 +00:00
|
|
|
let mut point = selection.end;
|
|
|
|
// Paste the text after the current selection
|
|
|
|
*point.column_mut() = point.column() + 1;
|
|
|
|
let point = display_map
|
|
|
|
.clip_point(point, Bias::Right)
|
|
|
|
.to_point(&display_map);
|
|
|
|
|
|
|
|
new_selections.push(selection.map(|_| point));
|
|
|
|
point
|
2022-05-20 00:42:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if linewise && to_insert.ends_with('\n') {
|
|
|
|
edits.push((
|
2022-07-08 17:57:02 +00:00
|
|
|
insert_at..insert_at,
|
2022-05-20 00:42:30 +00:00
|
|
|
&to_insert[0..to_insert.len().saturating_sub(1)],
|
|
|
|
))
|
|
|
|
} else {
|
2022-07-08 17:57:02 +00:00
|
|
|
edits.push((insert_at..insert_at, to_insert));
|
2022-05-20 00:42:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
drop(snapshot);
|
2022-07-29 05:34:56 +00:00
|
|
|
buffer.edit(edits, Some(AutoindentMode::EachLine), cx);
|
2022-05-20 00:42:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
editor.change_selections(Some(Autoscroll::Fit), cx, |s| {
|
|
|
|
s.select(new_selections)
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
editor.insert(&clipboard_text, cx);
|
|
|
|
}
|
|
|
|
}
|
2022-07-08 17:57:02 +00:00
|
|
|
editor.set_clip_at_line_ends(true, cx);
|
2022-05-20 00:42:30 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:58:28 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use indoc::indoc;
|
2022-08-04 17:23:03 +00:00
|
|
|
use util::test::marked_text_offsets;
|
2022-03-28 00:58:28 +00:00
|
|
|
|
2022-04-15 23:00:44 +00:00
|
|
|
use crate::{
|
|
|
|
state::{
|
|
|
|
Mode::{self, *},
|
|
|
|
Namespace, Operator,
|
|
|
|
},
|
2022-10-06 03:19:30 +00:00
|
|
|
test_contexts::VimTestContext,
|
2022-04-15 23:00:44 +00:00
|
|
|
};
|
2022-03-28 00:58:28 +00:00
|
|
|
|
|
|
|
#[gpui::test]
|
2022-04-21 23:14:58 +00:00
|
|
|
async fn test_h(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["h"]);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("The qˇuick", "The ˇquick");
|
|
|
|
cx.assert("ˇThe quick", "ˇThe quick");
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇbrown"},
|
2022-04-21 23:14:58 +00:00
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇbrown"},
|
2022-04-21 23:14:58 +00:00
|
|
|
);
|
|
|
|
}
|
2022-03-28 00:58:28 +00:00
|
|
|
|
2022-04-21 23:14:58 +00:00
|
|
|
#[gpui::test]
|
2022-04-22 16:43:15 +00:00
|
|
|
async fn test_backspace(cx: &mut gpui::TestAppContext) {
|
2022-04-21 23:14:58 +00:00
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
2022-04-22 16:43:15 +00:00
|
|
|
let mut cx = cx.binding(["backspace"]);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("The qˇuick", "The ˇquick");
|
|
|
|
cx.assert("ˇThe quick", "ˇThe quick");
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇbrown"},
|
2022-04-21 23:14:58 +00:00
|
|
|
indoc! {"
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇbrown"},
|
2022-04-21 23:14:58 +00:00
|
|
|
);
|
|
|
|
}
|
2022-03-28 00:58:28 +00:00
|
|
|
|
2022-04-21 23:14:58 +00:00
|
|
|
#[gpui::test]
|
|
|
|
async fn test_j(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["j"]);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇquick
|
2022-04-21 23:14:58 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
browˇn fox"},
|
2022-04-21 23:14:58 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
browˇn fox"},
|
2022-04-21 23:14:58 +00:00
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
browˇn fox"},
|
2022-04-21 23:14:58 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quicˇk
|
2022-04-21 23:14:58 +00:00
|
|
|
brown"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
browˇn"},
|
2022-04-21 23:14:58 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇbrown"},
|
2022-04-21 23:14:58 +00:00
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇbrown"},
|
2022-04-21 23:14:58 +00:00
|
|
|
);
|
|
|
|
}
|
2022-03-28 00:58:28 +00:00
|
|
|
|
2022-04-21 23:14:58 +00:00
|
|
|
#[gpui::test]
|
|
|
|
async fn test_k(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["k"]);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇquick
|
2022-04-21 23:14:58 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇquick
|
2022-04-21 23:14:58 +00:00
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
browˇn fox"},
|
2022-04-21 23:14:58 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇquick
|
2022-04-21 23:14:58 +00:00
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The
|
2022-08-04 00:52:34 +00:00
|
|
|
quicˇk"},
|
2022-04-21 23:14:58 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
Thˇe
|
2022-04-21 23:14:58 +00:00
|
|
|
quick"},
|
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 16:43:15 +00:00
|
|
|
#[gpui::test]
|
|
|
|
async fn test_l(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["l"]);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("The qˇuick", "The quˇick");
|
|
|
|
cx.assert("The quicˇk", "The quicˇk");
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quicˇk
|
2022-04-22 16:43:15 +00:00
|
|
|
brown"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quicˇk
|
2022-04-22 16:43:15 +00:00
|
|
|
brown"},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-28 00:58:28 +00:00
|
|
|
#[gpui::test]
|
|
|
|
async fn test_jump_to_line_boundaries(cx: &mut gpui::TestAppContext) {
|
2022-04-21 23:14:58 +00:00
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
2022-07-27 10:19:01 +00:00
|
|
|
let mut cx = cx.binding(["$"]);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("Tˇest test", "Test tesˇt");
|
|
|
|
cx.assert("Test tesˇt", "Test tesˇt");
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇquick
|
2022-04-21 23:14:58 +00:00
|
|
|
brown"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quicˇk
|
2022-04-21 23:14:58 +00:00
|
|
|
brown"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quicˇk
|
2022-04-21 23:14:58 +00:00
|
|
|
brown"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quicˇk
|
2022-04-21 23:14:58 +00:00
|
|
|
brown"},
|
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
|
2022-04-21 23:14:58 +00:00
|
|
|
let mut cx = cx.binding(["0"]);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("Test ˇtest", "ˇTest test");
|
|
|
|
cx.assert("ˇTest test", "ˇTest test");
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇquick
|
2022-04-21 23:14:58 +00:00
|
|
|
brown"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇThe quick
|
2022-04-21 23:14:58 +00:00
|
|
|
brown"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇThe quick
|
2022-04-21 23:14:58 +00:00
|
|
|
brown"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇThe quick
|
2022-04-21 23:14:58 +00:00
|
|
|
brown"},
|
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_jump_to_end(cx: &mut gpui::TestAppContext) {
|
2022-04-21 23:14:58 +00:00
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
2022-07-27 10:19:01 +00:00
|
|
|
let mut cx = cx.binding(["shift-g"]);
|
2022-04-19 18:36:44 +00:00
|
|
|
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.assert(
|
2022-04-19 18:36:44 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇquick
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
brown fox jumps
|
|
|
|
over the lazy dog"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
|
|
|
|
brown fox jumps
|
2022-08-04 00:52:34 +00:00
|
|
|
overˇ the lazy dog"},
|
2022-04-19 18:36:44 +00:00
|
|
|
);
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
|
|
|
|
brown fox jumps
|
2022-08-04 00:52:34 +00:00
|
|
|
overˇ the lazy dog"},
|
2022-04-21 23:14:58 +00:00
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
|
|
|
|
brown fox jumps
|
2022-08-04 00:52:34 +00:00
|
|
|
overˇ the lazy dog"},
|
2022-04-21 23:14:58 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quiˇck
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
brown"},
|
|
|
|
indoc! {"
|
2022-03-28 00:58:28 +00:00
|
|
|
The quick
|
|
|
|
|
2022-08-04 00:52:34 +00:00
|
|
|
browˇn"},
|
2022-04-21 23:14:58 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quiˇck
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
"},
|
|
|
|
indoc! {"
|
2022-03-28 00:58:28 +00:00
|
|
|
The quick
|
|
|
|
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ"},
|
2022-04-21 23:14:58 +00:00
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
2022-04-22 16:43:15 +00:00
|
|
|
async fn test_w(cx: &mut gpui::TestAppContext) {
|
2022-04-21 23:14:58 +00:00
|
|
|
let mut cx = VimTestContext::new(cx, true).await;
|
2022-08-04 17:23:03 +00:00
|
|
|
let (_, cursor_offsets) = marked_text_offsets(indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇquickˇ-ˇbrown
|
|
|
|
ˇ
|
|
|
|
ˇ
|
|
|
|
ˇfox_jumps ˇover
|
|
|
|
ˇthˇˇe"});
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.set_state(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇThe quick-brown
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
fox_jumps over
|
|
|
|
the"},
|
|
|
|
Mode::Normal,
|
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
|
|
|
|
for cursor_offset in cursor_offsets {
|
|
|
|
cx.simulate_keystroke("w");
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert_editor_selections(vec![cursor_offset..cursor_offset]);
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset and test ignoring punctuation
|
2022-08-04 17:23:03 +00:00
|
|
|
let (_, cursor_offsets) = marked_text_offsets(indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇquick-brown
|
|
|
|
ˇ
|
|
|
|
ˇ
|
|
|
|
ˇfox_jumps ˇover
|
|
|
|
ˇthˇˇe"});
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.set_state(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇThe quick-brown
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
fox_jumps over
|
|
|
|
the"},
|
|
|
|
Mode::Normal,
|
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
|
|
|
|
for cursor_offset in cursor_offsets {
|
2022-07-27 10:19:01 +00:00
|
|
|
cx.simulate_keystroke("shift-w");
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert_editor_selections(vec![cursor_offset..cursor_offset]);
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
2022-04-22 16:43:15 +00:00
|
|
|
async fn test_e(cx: &mut gpui::TestAppContext) {
|
2022-04-21 23:14:58 +00:00
|
|
|
let mut cx = VimTestContext::new(cx, true).await;
|
2022-08-04 17:23:03 +00:00
|
|
|
let (_, cursor_offsets) = marked_text_offsets(indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
Thˇe quicˇkˇ-browˇn
|
2022-03-28 00:58:28 +00:00
|
|
|
|
|
|
|
|
2022-08-04 00:52:34 +00:00
|
|
|
fox_jumpˇs oveˇr
|
|
|
|
thˇe"});
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.set_state(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇThe quick-brown
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
fox_jumps over
|
|
|
|
the"},
|
|
|
|
Mode::Normal,
|
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
|
|
|
|
for cursor_offset in cursor_offsets {
|
|
|
|
cx.simulate_keystroke("e");
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert_editor_selections(vec![cursor_offset..cursor_offset]);
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset and test ignoring punctuation
|
2022-08-04 17:23:03 +00:00
|
|
|
let (_, cursor_offsets) = marked_text_offsets(indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
Thˇe quick-browˇn
|
2022-03-28 00:58:28 +00:00
|
|
|
|
|
|
|
|
2022-08-04 00:52:34 +00:00
|
|
|
fox_jumpˇs oveˇr
|
|
|
|
thˇˇe"});
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.set_state(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇThe quick-brown
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
fox_jumps over
|
|
|
|
the"},
|
|
|
|
Mode::Normal,
|
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
for cursor_offset in cursor_offsets {
|
2022-07-27 10:19:01 +00:00
|
|
|
cx.simulate_keystroke("shift-e");
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert_editor_selections(vec![cursor_offset..cursor_offset]);
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
2022-04-22 16:43:15 +00:00
|
|
|
async fn test_b(cx: &mut gpui::TestAppContext) {
|
2022-04-21 23:14:58 +00:00
|
|
|
let mut cx = VimTestContext::new(cx, true).await;
|
2022-08-04 17:23:03 +00:00
|
|
|
let (_, cursor_offsets) = marked_text_offsets(indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇˇThe ˇquickˇ-ˇbrown
|
|
|
|
ˇ
|
|
|
|
ˇ
|
|
|
|
ˇfox_jumps ˇover
|
|
|
|
ˇthe"});
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.set_state(
|
|
|
|
indoc! {"
|
|
|
|
The quick-brown
|
|
|
|
|
|
|
|
|
|
|
|
fox_jumps over
|
2022-08-04 00:52:34 +00:00
|
|
|
thˇe"},
|
2022-04-21 23:14:58 +00:00
|
|
|
Mode::Normal,
|
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
|
|
|
|
for cursor_offset in cursor_offsets.into_iter().rev() {
|
|
|
|
cx.simulate_keystroke("b");
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert_editor_selections(vec![cursor_offset..cursor_offset]);
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reset and test ignoring punctuation
|
2022-08-04 17:23:03 +00:00
|
|
|
let (_, cursor_offsets) = marked_text_offsets(indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇˇThe ˇquick-brown
|
|
|
|
ˇ
|
|
|
|
ˇ
|
|
|
|
ˇfox_jumps ˇover
|
|
|
|
ˇthe"});
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.set_state(
|
|
|
|
indoc! {"
|
|
|
|
The quick-brown
|
|
|
|
|
|
|
|
|
|
|
|
fox_jumps over
|
2022-08-04 00:52:34 +00:00
|
|
|
thˇe"},
|
2022-04-21 23:14:58 +00:00
|
|
|
Mode::Normal,
|
|
|
|
);
|
2022-03-28 00:58:28 +00:00
|
|
|
for cursor_offset in cursor_offsets.into_iter().rev() {
|
2022-07-27 10:19:01 +00:00
|
|
|
cx.simulate_keystroke("shift-b");
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert_editor_selections(vec![cursor_offset..cursor_offset]);
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-15 23:00:44 +00:00
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_g_prefix_and_abort(cx: &mut gpui::TestAppContext) {
|
2022-04-21 23:14:58 +00:00
|
|
|
let mut cx = VimTestContext::new(cx, true).await;
|
2022-04-15 23:00:44 +00:00
|
|
|
|
|
|
|
// Can abort with escape to get back to normal mode
|
|
|
|
cx.simulate_keystroke("g");
|
|
|
|
assert_eq!(cx.mode(), Normal);
|
|
|
|
assert_eq!(
|
|
|
|
cx.active_operator(),
|
|
|
|
Some(Operator::Namespace(Namespace::G))
|
|
|
|
);
|
|
|
|
cx.simulate_keystroke("escape");
|
|
|
|
assert_eq!(cx.mode(), Normal);
|
|
|
|
assert_eq!(cx.active_operator(), None);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
2022-04-22 16:43:15 +00:00
|
|
|
async fn test_gg(cx: &mut gpui::TestAppContext) {
|
2022-04-21 23:14:58 +00:00
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["g", "g"]);
|
|
|
|
cx.assert(
|
2022-04-19 18:36:44 +00:00
|
|
|
indoc! {"
|
2022-04-21 23:14:58 +00:00
|
|
|
The quick
|
2022-04-15 23:00:44 +00:00
|
|
|
|
2022-04-21 23:14:58 +00:00
|
|
|
brown fox jumps
|
2022-08-04 00:52:34 +00:00
|
|
|
over ˇthe lazy dog"},
|
2022-04-15 23:00:44 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
brown fox jumps
|
|
|
|
over the lazy dog"},
|
2022-04-15 23:00:44 +00:00
|
|
|
);
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.assert(
|
2022-04-19 18:36:44 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
brown fox jumps
|
|
|
|
over the lazy dog"},
|
2022-04-19 18:36:44 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
brown fox jumps
|
|
|
|
over the lazy dog"},
|
2022-04-19 18:36:44 +00:00
|
|
|
);
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.assert(
|
2022-04-19 18:36:44 +00:00
|
|
|
indoc! {"
|
2022-04-21 23:14:58 +00:00
|
|
|
The quick
|
|
|
|
|
|
|
|
brown fox jumps
|
2022-08-04 00:52:34 +00:00
|
|
|
over the laˇzy dog"},
|
2022-04-19 18:36:44 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quicˇk
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
brown fox jumps
|
|
|
|
over the lazy dog"},
|
2022-04-19 18:36:44 +00:00
|
|
|
);
|
2022-04-21 23:14:58 +00:00
|
|
|
cx.assert(
|
2022-04-19 18:36:44 +00:00
|
|
|
indoc! {"
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
brown fox jumps
|
2022-08-04 00:52:34 +00:00
|
|
|
over the laˇzy dog"},
|
2022-04-19 18:36:44 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-21 23:14:58 +00:00
|
|
|
|
|
|
|
brown fox jumps
|
|
|
|
over the lazy dog"},
|
2022-04-19 18:36:44 +00:00
|
|
|
);
|
2022-04-15 23:00:44 +00:00
|
|
|
}
|
2022-04-22 16:43:15 +00:00
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_a(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["a"]).mode_after(Mode::Insert);
|
|
|
|
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("The qˇuick", "The quˇick");
|
|
|
|
cx.assert("The quicˇk", "The quickˇ");
|
2022-04-22 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_insert_end_of_line(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
2022-07-27 10:19:01 +00:00
|
|
|
let mut cx = cx.binding(["shift-a"]).mode_after(Mode::Insert);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("The qˇuick", "The quickˇ");
|
|
|
|
cx.assert("The qˇuick ", "The quick ˇ");
|
|
|
|
cx.assert("ˇ", "ˇ");
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The quickˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick"},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_jump_to_first_non_whitespace(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
2022-07-27 10:19:01 +00:00
|
|
|
let mut cx = cx.binding(["^"]);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("The qˇuick", "ˇThe quick");
|
|
|
|
cx.assert(" The qˇuick", " ˇThe quick");
|
|
|
|
cx.assert("ˇ", "ˇ");
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇThe quick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick"},
|
|
|
|
);
|
2022-05-24 20:35:57 +00:00
|
|
|
// Indoc disallows trailing whitspace.
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert(" ˇ \nThe quick", " ˇ \nThe quick");
|
2022-04-22 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_insert_first_non_whitespace(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
2022-07-27 10:19:01 +00:00
|
|
|
let mut cx = cx.binding(["shift-i"]).mode_after(Mode::Insert);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("The qˇuick", "ˇThe quick");
|
|
|
|
cx.assert(" The qˇuick", " ˇThe quick");
|
|
|
|
cx.assert("ˇ", "ˇ");
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇThe quick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick"},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_delete_to_end_of_line(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
2022-07-27 10:19:01 +00:00
|
|
|
let mut cx = cx.binding(["shift-d"]);
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The ˇq
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_x(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["x"]);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("ˇTest", "ˇest");
|
|
|
|
cx.assert("Teˇst", "Teˇt");
|
|
|
|
cx.assert("Tesˇt", "Teˇs");
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
Tesˇt
|
2022-04-22 16:43:15 +00:00
|
|
|
test"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
Teˇs
|
2022-04-22 16:43:15 +00:00
|
|
|
test"},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_delete_left(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
2022-07-27 10:19:01 +00:00
|
|
|
let mut cx = cx.binding(["shift-x"]);
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("Teˇst", "Tˇst");
|
|
|
|
cx.assert("Tˇest", "ˇest");
|
|
|
|
cx.assert("ˇTest", "ˇTest");
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
Test
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇtest"},
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
|
|
|
Test
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇtest"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_o(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["o"]).mode_after(Mode::Insert);
|
|
|
|
|
|
|
|
cx.assert(
|
2022-08-04 00:52:34 +00:00
|
|
|
"ˇ",
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
|
|
|
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
2022-08-04 00:52:34 +00:00
|
|
|
"The ˇquick",
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
brown ˇfox
|
2022-04-22 16:43:15 +00:00
|
|
|
jumps over"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
brown fox
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
jumps over"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
brown fox
|
2022-08-04 00:52:34 +00:00
|
|
|
jumps ˇover"},
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
brown fox
|
|
|
|
jumps over
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox
|
|
|
|
jumps over"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox
|
|
|
|
jumps over"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
fn test() {
|
|
|
|
println!(ˇ);
|
|
|
|
}
|
|
|
|
"},
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
fn test() {
|
2022-04-22 16:43:15 +00:00
|
|
|
println!();
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
|
|
|
}
|
|
|
|
"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
fn test(ˇ) {
|
|
|
|
println!();
|
|
|
|
}"},
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
fn test() {
|
|
|
|
ˇ
|
|
|
|
println!();
|
|
|
|
}"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_insert_line_above(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
2022-07-27 10:19:01 +00:00
|
|
|
let mut cx = cx.binding(["shift-o"]).mode_after(Mode::Insert);
|
2022-04-22 16:43:15 +00:00
|
|
|
|
|
|
|
cx.assert(
|
2022-08-04 00:52:34 +00:00
|
|
|
"ˇ",
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
2022-08-04 00:52:34 +00:00
|
|
|
"The ˇquick",
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
brown ˇfox
|
2022-04-22 16:43:15 +00:00
|
|
|
jumps over"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox
|
|
|
|
jumps over"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
brown fox
|
2022-08-04 00:52:34 +00:00
|
|
|
jumps ˇover"},
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
brown fox
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
jumps over"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox
|
|
|
|
jumps over"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
The quick
|
|
|
|
brown fox
|
|
|
|
jumps over"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
|
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-05-03 17:29:57 +00:00
|
|
|
fn test()
|
2022-08-04 00:52:34 +00:00
|
|
|
println!(ˇ);"},
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
2022-05-03 17:29:57 +00:00
|
|
|
fn test()
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-05-03 17:29:57 +00:00
|
|
|
println!();"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
fn test(ˇ) {
|
|
|
|
println!();
|
|
|
|
}"},
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
|
|
|
fn test() {
|
|
|
|
println!();
|
|
|
|
}"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_dd(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["d", "d"]);
|
|
|
|
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("ˇ", "ˇ");
|
|
|
|
cx.assert("The ˇquick", "ˇ");
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
brown ˇfox
|
2022-04-22 16:43:15 +00:00
|
|
|
jumps over"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
jumps ˇover"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
brown fox
|
2022-08-04 00:52:34 +00:00
|
|
|
jumps ˇover"},
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
brown ˇfox"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox
|
|
|
|
jumps over"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
brownˇ fox
|
2022-04-22 16:43:15 +00:00
|
|
|
jumps over"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇbrown fox"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_cc(cx: &mut gpui::TestAppContext) {
|
|
|
|
let cx = VimTestContext::new(cx, true).await;
|
|
|
|
let mut cx = cx.binding(["c", "c"]).mode_after(Mode::Insert);
|
|
|
|
|
2022-08-04 00:52:34 +00:00
|
|
|
cx.assert("ˇ", "ˇ");
|
|
|
|
cx.assert("The ˇquick", "ˇ");
|
2022-04-22 16:43:15 +00:00
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
brown ˇfox
|
2022-04-22 16:43:15 +00:00
|
|
|
jumps over"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
jumps over"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
brown fox
|
2022-08-04 00:52:34 +00:00
|
|
|
jumps ˇover"},
|
2022-04-22 16:43:15 +00:00
|
|
|
indoc! {"
|
|
|
|
The quick
|
|
|
|
brown fox
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ"},
|
2022-04-22 16:43:15 +00:00
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
The qˇuick
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox
|
|
|
|
jumps over"},
|
|
|
|
indoc! {"
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox
|
|
|
|
jumps over"},
|
|
|
|
);
|
|
|
|
cx.assert(
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
indoc! {"
|
|
|
|
The quick
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇ
|
2022-04-22 16:43:15 +00:00
|
|
|
brown fox"},
|
|
|
|
);
|
|
|
|
}
|
2022-05-20 00:42:30 +00:00
|
|
|
|
|
|
|
#[gpui::test]
|
|
|
|
async fn test_p(cx: &mut gpui::TestAppContext) {
|
|
|
|
let mut cx = VimTestContext::new(cx, true).await;
|
|
|
|
cx.set_state(
|
|
|
|
indoc! {"
|
2022-05-23 18:04:26 +00:00
|
|
|
The quick brown
|
2022-08-04 00:52:34 +00:00
|
|
|
fox juˇmps over
|
2022-05-23 18:04:26 +00:00
|
|
|
the lazy dog"},
|
2022-05-20 00:42:30 +00:00
|
|
|
Mode::Normal,
|
|
|
|
);
|
|
|
|
|
|
|
|
cx.simulate_keystrokes(["d", "d"]);
|
|
|
|
cx.assert_editor_state(indoc! {"
|
|
|
|
The quick brown
|
2022-08-04 00:52:34 +00:00
|
|
|
the laˇzy dog"});
|
2022-05-20 00:42:30 +00:00
|
|
|
|
|
|
|
cx.simulate_keystroke("p");
|
2022-07-08 17:57:02 +00:00
|
|
|
cx.assert_state(
|
|
|
|
indoc! {"
|
|
|
|
The quick brown
|
|
|
|
the lazy dog
|
2022-08-04 00:52:34 +00:00
|
|
|
ˇfox jumps over"},
|
2022-07-08 17:57:02 +00:00
|
|
|
Mode::Normal,
|
|
|
|
);
|
2022-05-26 18:28:05 +00:00
|
|
|
|
|
|
|
cx.set_state(
|
|
|
|
indoc! {"
|
|
|
|
The quick brown
|
2022-08-04 00:52:34 +00:00
|
|
|
fox «jumpˇ»s over
|
2022-05-26 18:28:05 +00:00
|
|
|
the lazy dog"},
|
2022-06-30 19:32:53 +00:00
|
|
|
Mode::Visual { line: false },
|
2022-05-26 18:28:05 +00:00
|
|
|
);
|
|
|
|
cx.simulate_keystroke("y");
|
|
|
|
cx.set_state(
|
|
|
|
indoc! {"
|
|
|
|
The quick brown
|
2022-08-04 00:52:34 +00:00
|
|
|
fox jumps oveˇr
|
2022-05-26 18:28:05 +00:00
|
|
|
the lazy dog"},
|
|
|
|
Mode::Normal,
|
|
|
|
);
|
|
|
|
cx.simulate_keystroke("p");
|
2022-07-08 17:57:02 +00:00
|
|
|
cx.assert_state(
|
|
|
|
indoc! {"
|
|
|
|
The quick brown
|
2022-08-04 00:52:34 +00:00
|
|
|
fox jumps overˇjumps
|
2022-07-08 17:57:02 +00:00
|
|
|
the lazy dog"},
|
|
|
|
Mode::Normal,
|
|
|
|
);
|
2022-05-20 00:42:30 +00:00
|
|
|
}
|
2022-03-28 00:58:28 +00:00
|
|
|
}
|