Merge branch 'main' into helix-match-upstream

This commit is contained in:
fantacell 2025-08-12 23:07:41 +02:00
commit 80234444cf
966 changed files with 51527 additions and 16808 deletions

View file

@ -31,7 +31,7 @@ impl Vim {
) {
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
if let Some(selections) = editor
.change_list
.next_change(count, direction)
@ -49,7 +49,7 @@ impl Vim {
}
pub(crate) fn push_to_change_list(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some((new_positions, buffer)) = self.update_editor(window, cx, |vim, editor, _, cx| {
let Some((new_positions, buffer)) = self.update_editor(cx, |vim, editor, cx| {
let (map, selections) = editor.selections.all_adjusted_display(cx);
let buffer = editor.buffer().clone();

View file

@ -241,9 +241,9 @@ impl Deref for WrappedAction {
pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
// Vim::action(editor, cx, |vim, action: &StartOfLine, window, cx| {
Vim::action(editor, cx, |vim, action: &VimSet, window, cx| {
Vim::action(editor, cx, |vim, action: &VimSet, _, cx| {
for option in action.options.iter() {
vim.update_editor(window, cx, |_, editor, _, cx| match option {
vim.update_editor(cx, |_, editor, cx| match option {
VimOption::Wrap(true) => {
editor
.set_soft_wrap_mode(language::language_settings::SoftWrap::EditorWidth, cx);
@ -298,7 +298,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
});
Vim::action(editor, cx, |vim, action: &VimSave, window, cx| {
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
let Some(project) = editor.project.clone() else {
return;
};
@ -375,7 +375,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
cx,
);
}
vim.update_editor(window, cx, |vim, editor, window, cx| match action {
vim.update_editor(cx, |vim, editor, cx| match action {
DeleteMarks::Marks(s) => {
if s.starts_with('-') || s.ends_with('-') || s.contains(['\'', '`']) {
err(s.clone(), window, cx);
@ -432,7 +432,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
});
Vim::action(editor, cx, |vim, action: &VimEdit, window, cx| {
vim.update_editor(window, cx, |vim, editor, window, cx| {
vim.update_editor(cx, |vim, editor, cx| {
let Some(workspace) = vim.workspace(window) else {
return;
};
@ -462,11 +462,10 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
.map(|c| Keystroke::parse(&c.to_string()).unwrap())
.collect();
vim.switch_mode(Mode::Normal, true, window, cx);
let initial_selections = vim.update_editor(window, cx, |_, editor, _, _| {
editor.selections.disjoint_anchors()
});
let initial_selections =
vim.update_editor(cx, |_, editor, _| editor.selections.disjoint_anchors());
if let Some(range) = &action.range {
let result = vim.update_editor(window, cx, |vim, editor, window, cx| {
let result = vim.update_editor(cx, |vim, editor, cx| {
let range = range.buffer_range(vim, editor, window, cx)?;
editor.change_selections(
SelectionEffects::no_scroll().nav_history(false),
@ -498,7 +497,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
cx.spawn_in(window, async move |vim, cx| {
task.await;
vim.update_in(cx, |vim, window, cx| {
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
if had_range {
editor.change_selections(SelectionEffects::default(), window, cx, |s| {
s.select_anchor_ranges([s.newest_anchor().range()]);
@ -510,7 +509,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
} else {
vim.switch_mode(Mode::Normal, true, window, cx);
}
vim.update_editor(window, cx, |_, editor, _, cx| {
vim.update_editor(cx, |_, editor, cx| {
if let Some(first_sel) = initial_selections {
if let Some(tx_id) = editor
.buffer()
@ -548,7 +547,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, |vim, action: &GoToLine, window, cx| {
vim.switch_mode(Mode::Normal, false, window, cx);
let result = vim.update_editor(window, cx, |vim, editor, window, cx| {
let result = vim.update_editor(cx, |vim, editor, cx| {
let snapshot = editor.snapshot(window, cx);
let buffer_row = action.range.head().buffer_row(vim, editor, window, cx)?;
let current = editor.selections.newest::<Point>(cx);
@ -573,7 +572,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
});
Vim::action(editor, cx, |vim, action: &YankCommand, window, cx| {
vim.update_editor(window, cx, |vim, editor, window, cx| {
vim.update_editor(cx, |vim, editor, cx| {
let snapshot = editor.snapshot(window, cx);
if let Ok(range) = action.range.buffer_range(vim, editor, window, cx) {
let end = if range.end < snapshot.buffer_snapshot.max_row() {
@ -600,7 +599,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
});
Vim::action(editor, cx, |vim, action: &WithRange, window, cx| {
let result = vim.update_editor(window, cx, |vim, editor, window, cx| {
let result = vim.update_editor(cx, |vim, editor, cx| {
action.range.buffer_range(vim, editor, window, cx)
});
@ -619,7 +618,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
};
let previous_selections = vim
.update_editor(window, cx, |_, editor, window, cx| {
.update_editor(cx, |_, editor, cx| {
let selections = action.restore_selection.then(|| {
editor
.selections
@ -635,7 +634,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
.flatten();
window.dispatch_action(action.action.boxed_clone(), cx);
cx.defer_in(window, move |vim, window, cx| {
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
if let Some(previous_selections) = previous_selections {
s.select_ranges(previous_selections);
@ -1176,8 +1175,10 @@ fn generate_commands(_: &App) -> Vec<VimCommand> {
VimCommand::str(("ls", ""), "tab_switcher::ToggleAll"),
VimCommand::new(("new", ""), workspace::NewFileSplitHorizontal),
VimCommand::new(("vne", "w"), workspace::NewFileSplitVertical),
VimCommand::new(("tabe", "dit"), workspace::NewFile),
VimCommand::new(("tabnew", ""), workspace::NewFile),
VimCommand::new(("tabe", "dit"), workspace::NewFile)
.args(|_action, args| Some(VimEdit { filename: args }.boxed_clone())),
VimCommand::new(("tabnew", ""), workspace::NewFile)
.args(|_action, args| Some(VimEdit { filename: args }.boxed_clone())),
VimCommand::new(("tabn", "ext"), workspace::ActivateNextItem).count(),
VimCommand::new(("tabp", "revious"), workspace::ActivatePreviousItem).count(),
VimCommand::new(("tabN", "ext"), workspace::ActivatePreviousItem).count(),
@ -1536,7 +1537,7 @@ impl OnMatchingLines {
}
pub fn run(&self, vim: &mut Vim, window: &mut Window, cx: &mut Context<Vim>) {
let result = vim.update_editor(window, cx, |vim, editor, window, cx| {
let result = vim.update_editor(cx, |vim, editor, cx| {
self.range.buffer_range(vim, editor, window, cx)
});
@ -1600,7 +1601,7 @@ impl OnMatchingLines {
});
};
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
let snapshot = editor.snapshot(window, cx);
let mut row = range.start.0;
@ -1680,7 +1681,7 @@ pub struct ShellExec {
impl Vim {
pub fn cancel_running_command(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if self.running_command.take().is_some() {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, _window, _cx| {
editor.clear_row_highlights::<ShellExec>();
})
@ -1691,7 +1692,7 @@ impl Vim {
fn prepare_shell_command(
&mut self,
command: &str,
window: &mut Window,
_: &mut Window,
cx: &mut Context<Self>,
) -> String {
let mut ret = String::new();
@ -1711,7 +1712,7 @@ impl Vim {
}
match c {
'%' => {
self.update_editor(window, cx, |_, editor, _window, cx| {
self.update_editor(cx, |_, editor, cx| {
if let Some((_, buffer, _)) = editor.active_excerpt(cx) {
if let Some(file) = buffer.read(cx).file() {
if let Some(local) = file.as_local() {
@ -1747,7 +1748,7 @@ impl Vim {
let Some(workspace) = self.workspace(window) else {
return;
};
let command = self.update_editor(window, cx, |_, editor, window, cx| {
let command = self.update_editor(cx, |_, editor, cx| {
let snapshot = editor.snapshot(window, cx);
let start = editor.selections.newest_display(cx);
let text_layout_details = editor.text_layout_details(window);
@ -1794,7 +1795,7 @@ impl Vim {
let Some(workspace) = self.workspace(window) else {
return;
};
let command = self.update_editor(window, cx, |_, editor, window, cx| {
let command = self.update_editor(cx, |_, editor, cx| {
let snapshot = editor.snapshot(window, cx);
let start = editor.selections.newest_display(cx);
let range = object
@ -1896,7 +1897,7 @@ impl ShellExec {
let mut input_snapshot = None;
let mut input_range = None;
let mut needs_newline_prefix = false;
vim.update_editor(window, cx, |vim, editor, window, cx| {
vim.update_editor(cx, |vim, editor, cx| {
let snapshot = editor.buffer().read(cx).snapshot(cx);
let range = if let Some(range) = self.range.clone() {
let Some(range) = range.buffer_range(vim, editor, window, cx).log_err() else {
@ -1990,7 +1991,7 @@ impl ShellExec {
}
vim.update_in(cx, |vim, window, cx| {
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.edit([(range.clone(), text)], cx);
let snapshot = editor.buffer().read(cx).snapshot(cx);
@ -2477,4 +2478,110 @@ mod test {
"});
// Once ctrl-v to input character literals is added there should be a test for redo
}
#[gpui::test]
async fn test_command_tabnew(cx: &mut TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
// Create a new file to ensure that, when the filename is used with
// `:tabnew`, it opens the existing file in a new tab.
let fs = cx.workspace(|workspace, _, cx| workspace.project().read(cx).fs().clone());
fs.as_fake()
.insert_file(path!("/root/dir/file_2.rs"), "file_2".as_bytes().to_vec())
.await;
cx.simulate_keystrokes(": tabnew");
cx.simulate_keystrokes("enter");
cx.workspace(|workspace, _, cx| assert_eq!(workspace.items(cx).count(), 2));
// Assert that the new tab is empty and not associated with any file, as
// no file path was provided to the `:tabnew` command.
cx.workspace(|workspace, _window, cx| {
let active_editor = workspace.active_item_as::<Editor>(cx).unwrap();
let buffer = active_editor
.read(cx)
.buffer()
.read(cx)
.as_singleton()
.unwrap();
assert!(&buffer.read(cx).file().is_none());
});
// Leverage the filename as an argument to the `:tabnew` command,
// ensuring that the file, instead of an empty buffer, is opened in a
// new tab.
cx.simulate_keystrokes(": tabnew space dir/file_2.rs");
cx.simulate_keystrokes("enter");
cx.workspace(|workspace, _, cx| assert_eq!(workspace.items(cx).count(), 3));
cx.workspace(|workspace, _, cx| {
assert_active_item(workspace, path!("/root/dir/file_2.rs"), "file_2", cx);
});
// If the `filename` argument provided to the `:tabnew` command is for a
// file that doesn't yet exist, it should still associate the buffer
// with that file path, so that when the buffer contents are saved, the
// file is created.
cx.simulate_keystrokes(": tabnew space dir/file_3.rs");
cx.simulate_keystrokes("enter");
cx.workspace(|workspace, _, cx| assert_eq!(workspace.items(cx).count(), 4));
cx.workspace(|workspace, _, cx| {
assert_active_item(workspace, path!("/root/dir/file_3.rs"), "", cx);
});
}
#[gpui::test]
async fn test_command_tabedit(cx: &mut TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
// Create a new file to ensure that, when the filename is used with
// `:tabedit`, it opens the existing file in a new tab.
let fs = cx.workspace(|workspace, _, cx| workspace.project().read(cx).fs().clone());
fs.as_fake()
.insert_file(path!("/root/dir/file_2.rs"), "file_2".as_bytes().to_vec())
.await;
cx.simulate_keystrokes(": tabedit");
cx.simulate_keystrokes("enter");
cx.workspace(|workspace, _, cx| assert_eq!(workspace.items(cx).count(), 2));
// Assert that the new tab is empty and not associated with any file, as
// no file path was provided to the `:tabedit` command.
cx.workspace(|workspace, _window, cx| {
let active_editor = workspace.active_item_as::<Editor>(cx).unwrap();
let buffer = active_editor
.read(cx)
.buffer()
.read(cx)
.as_singleton()
.unwrap();
assert!(&buffer.read(cx).file().is_none());
});
// Leverage the filename as an argument to the `:tabedit` command,
// ensuring that the file, instead of an empty buffer, is opened in a
// new tab.
cx.simulate_keystrokes(": tabedit space dir/file_2.rs");
cx.simulate_keystrokes("enter");
cx.workspace(|workspace, _, cx| assert_eq!(workspace.items(cx).count(), 3));
cx.workspace(|workspace, _, cx| {
assert_active_item(workspace, path!("/root/dir/file_2.rs"), "file_2", cx);
});
// If the `filename` argument provided to the `:tabedit` command is for a
// file that doesn't yet exist, it should still associate the buffer
// with that file path, so that when the buffer contents are saved, the
// file is created.
cx.simulate_keystrokes(": tabedit space dir/file_3.rs");
cx.simulate_keystrokes("enter");
cx.workspace(|workspace, _, cx| assert_eq!(workspace.items(cx).count(), 4));
cx.workspace(|workspace, _, cx| {
assert_active_item(workspace, path!("/root/dir/file_3.rs"), "", cx);
});
}
}

View file

@ -56,9 +56,7 @@ impl Vim {
self.pop_operator(window, cx);
if self.editor_input_enabled() {
self.update_editor(window, cx, |_, editor, window, cx| {
editor.insert(&text, window, cx)
});
self.update_editor(cx, |_, editor, cx| editor.insert(&text, window, cx));
} else {
self.input_ignored(text, window, cx);
}
@ -214,9 +212,7 @@ impl Vim {
text.push_str(suffix);
if self.editor_input_enabled() {
self.update_editor(window, cx, |_, editor, window, cx| {
editor.insert(&text, window, cx)
});
self.update_editor(cx, |_, editor, cx| editor.insert(&text, window, cx));
} else {
self.input_ignored(text.into(), window, cx);
}

View file

@ -66,7 +66,7 @@ impl Vim {
cx: &mut Context<Self>,
mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool,
) {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| {
let times = times.unwrap_or(1);
@ -119,7 +119,7 @@ impl Vim {
cx: &mut Context<Self>,
mut is_boundary: impl FnMut(char, char, &CharClassifier) -> bool,
) {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| {
let times = times.unwrap_or(1);
@ -179,7 +179,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| {
@ -257,7 +257,7 @@ impl Vim {
})
}
Motion::FindForward { .. } => {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| {
@ -284,7 +284,7 @@ impl Vim {
});
}
Motion::FindBackward { .. } => {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| {
@ -316,7 +316,7 @@ impl Vim {
fn helix_insert(&mut self, _: &HelixInsert, window: &mut Window, cx: &mut Context<Self>) {
self.start_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|_map, selection| {
// In helix normal mode, move cursor to start of selection and collapse
@ -332,7 +332,7 @@ impl Vim {
fn helix_append(&mut self, _: &HelixAppend, window: &mut Window, cx: &mut Context<Self>) {
self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| {
let point = if selection.is_empty() {
@ -347,7 +347,7 @@ impl Vim {
}
pub fn helix_replace(&mut self, text: &str, window: &mut Window, cx: &mut Context<Self>) {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let (map, selections) = editor.selections.all_display(cx);

View file

@ -31,7 +31,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
vim.store_visual_marks(window, cx);
vim.update_editor(window, cx, |vim, editor, window, cx| {
vim.update_editor(cx, |vim, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let original_positions = vim.save_selection_starts(editor, cx);
for _ in 0..count {
@ -50,7 +50,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
vim.store_visual_marks(window, cx);
vim.update_editor(window, cx, |vim, editor, window, cx| {
vim.update_editor(cx, |vim, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let original_positions = vim.save_selection_starts(editor, cx);
for _ in 0..count {
@ -69,7 +69,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
vim.store_visual_marks(window, cx);
vim.update_editor(window, cx, |vim, editor, window, cx| {
vim.update_editor(cx, |vim, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let original_positions = vim.save_selection_starts(editor, cx);
for _ in 0..count {
@ -95,7 +95,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
let mut selection_starts: HashMap<_, _> = Default::default();
@ -137,7 +137,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let mut original_positions: HashMap<_, _> = Default::default();
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {

View file

@ -3,7 +3,9 @@ use editor::{Bias, Editor};
use gpui::{Action, Context, Window, actions};
use language::SelectionGoal;
use settings::Settings;
use text::Point;
use vim_mode_setting::HelixModeSetting;
use workspace::searchable::Direction;
actions!(
vim,
@ -11,13 +13,23 @@ actions!(
/// Switches to normal mode with cursor positioned before the current character.
NormalBefore,
/// Temporarily switches to normal mode for one command.
TemporaryNormal
TemporaryNormal,
/// Inserts the next character from the line above into the current line.
InsertFromAbove,
/// Inserts the next character from the line below into the current line.
InsertFromBelow
]
);
pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, Vim::normal_before);
Vim::action(editor, cx, Vim::temporary_normal);
Vim::action(editor, cx, |vim, _: &InsertFromAbove, window, cx| {
vim.insert_around(Direction::Prev, window, cx)
});
Vim::action(editor, cx, |vim, _: &InsertFromBelow, window, cx| {
vim.insert_around(Direction::Next, window, cx)
})
}
impl Vim {
@ -38,7 +50,7 @@ impl Vim {
if count <= 1 || Vim::globals(cx).dot_replaying {
self.create_mark("^".into(), window, cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.dismiss_menus_and_popups(false, window, cx);
if !HelixModeSetting::get_global(cx).0 {
@ -71,6 +83,29 @@ impl Vim {
self.switch_mode(Mode::Normal, true, window, cx);
self.temp_mode = true;
}
fn insert_around(&mut self, direction: Direction, _: &mut Window, cx: &mut Context<Self>) {
self.update_editor(cx, |_, editor, cx| {
let snapshot = editor.buffer().read(cx).snapshot(cx);
let mut edits = Vec::new();
for selection in editor.selections.all::<Point>(cx) {
let point = selection.head();
let new_row = match direction {
Direction::Next => point.row + 1,
Direction::Prev if point.row > 0 => point.row - 1,
_ => continue,
};
let source = snapshot.clip_point(Point::new(new_row, point.column), Bias::Left);
if let Some(c) = snapshot.chars_at(source).next()
&& c != '\n'
{
edits.push((point..point, c.to_string()))
}
}
editor.edit(edits, cx);
});
}
}
#[cfg(test)]
@ -156,4 +191,13 @@ mod test {
.await;
cx.shared_state().await.assert_eq("hehello\nˇllo\n");
}
#[gpui::test]
async fn test_insert_ctrl_y(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state("hello\nˇ\nworld").await;
cx.simulate_shared_keystrokes("i ctrl-y ctrl-e").await;
cx.shared_state().await.assert_eq("hello\nhoˇ\nworld");
}
}

View file

@ -679,7 +679,7 @@ impl Vim {
match self.mode {
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => {
if !prior_selections.is_empty() {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges(prior_selections.iter().cloned())
})
@ -987,7 +987,7 @@ impl Motion {
SelectionGoal::None,
),
NextWordEnd { ignore_punctuation } => (
next_word_end(map, point, *ignore_punctuation, times, true),
next_word_end(map, point, *ignore_punctuation, times, true, true),
SelectionGoal::None,
),
PreviousWordStart { ignore_punctuation } => (
@ -1723,14 +1723,19 @@ pub(crate) fn next_word_end(
ignore_punctuation: bool,
times: usize,
allow_cross_newline: bool,
always_advance: bool,
) -> DisplayPoint {
let classifier = map
.buffer_snapshot
.char_classifier_at(point.to_point(map))
.ignore_punctuation(ignore_punctuation);
for _ in 0..times {
let new_point = next_char(map, point, allow_cross_newline);
let mut need_next_char = false;
let new_point = if always_advance {
next_char(map, point, allow_cross_newline)
} else {
point
};
let new_point = movement::find_boundary_exclusive(
map,
new_point,
@ -3803,7 +3808,7 @@ mod test {
cx.update_editor(|editor, _window, cx| {
let range = editor.selections.newest_anchor().range();
let inlay_text = " field: int,\n field2: string\n field3: float";
let inlay = Inlay::inline_completion(1, range.start, inlay_text);
let inlay = Inlay::edit_prediction(1, range.start, inlay_text);
editor.splice_inlays(&[], vec![inlay], cx);
});
@ -3835,7 +3840,7 @@ mod test {
let end_of_line =
snapshot.anchor_after(Point::new(0, snapshot.line_len(MultiBufferRow(0))));
let inlay_text = " hint";
let inlay = Inlay::inline_completion(1, end_of_line, inlay_text);
let inlay = Inlay::edit_prediction(1, end_of_line, inlay_text);
editor.splice_inlays(&[], vec![inlay], cx);
});
cx.simulate_keystrokes("$");

View file

@ -132,7 +132,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, |vim, _: &HelixDelete, window, cx| {
vim.record_current_action(cx);
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| {
if selection.is_empty() {
@ -146,7 +146,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
});
Vim::action(editor, cx, |vim, _: &HelixCollapseSelection, window, cx| {
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| {
let mut point = selection.head();
@ -198,7 +198,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, |vim, _: &Undo, window, cx| {
let times = Vim::take_count(cx);
Vim::take_forced_motion(cx);
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
for _ in 0..times.unwrap_or(1) {
editor.undo(&editor::actions::Undo, window, cx);
}
@ -207,7 +207,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::action(editor, cx, |vim, _: &Redo, window, cx| {
let times = Vim::take_count(cx);
Vim::take_forced_motion(cx);
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
for _ in 0..times.unwrap_or(1) {
editor.redo(&editor::actions::Redo, window, cx);
}
@ -215,7 +215,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
});
Vim::action(editor, cx, |vim, _: &UndoLastLine, window, cx| {
Vim::take_forced_motion(cx);
vim.update_editor(window, cx, |vim, editor, window, cx| {
vim.update_editor(cx, |vim, editor, cx| {
let snapshot = editor.buffer().read(cx).snapshot(cx);
let Some(last_change) = editor.change_list.last_before_grouping() else {
return;
@ -535,7 +535,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.change_selections(
SelectionEffects::default().nav_history(motion.push_to_jump_list()),
@ -555,7 +555,7 @@ impl Vim {
fn insert_after(&mut self, _: &InsertAfter, window: &mut Window, cx: &mut Context<Self>) {
self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| (right(map, cursor, 1), SelectionGoal::None));
});
@ -566,7 +566,7 @@ impl Vim {
self.start_recording(cx);
if self.mode.is_visual() {
let current_mode = self.mode;
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| {
if current_mode == Mode::VisualLine {
@ -590,7 +590,7 @@ impl Vim {
) {
self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| {
(
@ -610,7 +610,7 @@ impl Vim {
) {
self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| {
(next_line_end(map, cursor, 1), SelectionGoal::None)
@ -627,7 +627,7 @@ impl Vim {
) {
self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let Some(Mark::Local(marks)) = vim.get_mark("^", editor, window, cx) else {
return;
};
@ -646,7 +646,7 @@ impl Vim {
) {
self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let selections = editor.selections.all::<Point>(cx);
let snapshot = editor.buffer().read(cx).snapshot(cx);
@ -687,7 +687,7 @@ impl Vim {
) {
self.start_recording(cx);
self.switch_mode(Mode::Insert, false, window, cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
let selections = editor.selections.all::<Point>(cx);
@ -734,7 +734,7 @@ impl Vim {
self.record_current_action(cx);
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, _, cx| {
let selections = editor.selections.all::<Point>(cx);
@ -763,7 +763,7 @@ impl Vim {
self.record_current_action(cx);
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let selections = editor.selections.all::<Point>(cx);
let snapshot = editor.buffer().read(cx).snapshot(cx);
@ -813,7 +813,7 @@ impl Vim {
times -= 1;
}
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
for _ in 0..times {
editor.join_lines_impl(insert_whitespace, window, cx)
@ -837,10 +837,10 @@ impl Vim {
)
}
fn show_location(&mut self, _: &ShowLocation, window: &mut Window, cx: &mut Context<Self>) {
fn show_location(&mut self, _: &ShowLocation, _: &mut Window, cx: &mut Context<Self>) {
let count = Vim::take_count(cx);
Vim::take_forced_motion(cx);
self.update_editor(window, cx, |vim, editor, _window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let selection = editor.selections.newest_anchor();
let Some((buffer, point, _)) = editor
.buffer()
@ -884,7 +884,7 @@ impl Vim {
fn toggle_comments(&mut self, _: &ToggleComments, window: &mut Window, cx: &mut Context<Self>) {
self.record_current_action(cx);
self.store_visual_marks(window, cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let original_positions = vim.save_selection_starts(editor, cx);
editor.toggle_comments(&Default::default(), window, cx);
@ -906,7 +906,7 @@ impl Vim {
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
let (map, display_selections) = editor.selections.all_display(cx);

View file

@ -34,7 +34,7 @@ impl Vim {
} else {
None
};
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
@ -51,6 +51,7 @@ impl Vim {
ignore_punctuation,
&text_layout_details,
motion == Motion::NextSubwordStart { ignore_punctuation },
!matches!(motion, Motion::NextWordStart { .. }),
)
}
_ => {
@ -89,7 +90,7 @@ impl Vim {
if let Some(kind) = motion_kind {
vim.copy_selections_content(editor, kind, window, cx);
editor.insert("", window, cx);
editor.refresh_inline_completion(true, false, window, cx);
editor.refresh_edit_prediction(true, false, window, cx);
}
});
});
@ -110,7 +111,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
let mut objects_found = false;
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
// We are swapping to insert mode anyway. Just set the line end clipping behavior now
editor.set_clip_at_line_ends(false, cx);
editor.transact(window, cx, |editor, window, cx| {
@ -122,7 +123,7 @@ impl Vim {
if objects_found {
vim.copy_selections_content(editor, MotionKind::Exclusive, window, cx);
editor.insert("", window, cx);
editor.refresh_inline_completion(true, false, window, cx);
editor.refresh_edit_prediction(true, false, window, cx);
}
});
});
@ -148,6 +149,7 @@ fn expand_changed_word_selection(
ignore_punctuation: bool,
text_layout_details: &TextLayoutDetails,
use_subword: bool,
always_advance: bool,
) -> Option<MotionKind> {
let is_in_word = || {
let classifier = map
@ -173,8 +175,14 @@ fn expand_changed_word_selection(
selection.end =
motion::next_subword_end(map, selection.end, ignore_punctuation, 1, false);
} else {
selection.end =
motion::next_word_end(map, selection.end, ignore_punctuation, 1, false);
selection.end = motion::next_word_end(
map,
selection.end,
ignore_punctuation,
1,
false,
always_advance,
);
}
selection.end = motion::next_char(map, selection.end, false);
}
@ -271,6 +279,10 @@ mod test {
cx.simulate("c shift-w", "Test teˇst-test test")
.await
.assert_matches();
// on last character of word, `cw` doesn't eat subsequent punctuation
// see https://github.com/zed-industries/zed/issues/35269
cx.simulate("c w", "tesˇt-test").await.assert_matches();
}
#[gpui::test]

View file

@ -31,7 +31,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.set_clip_at_line_ends(false, cx);
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
@ -87,7 +87,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
let mut original_positions: HashMap<_, _> = Default::default();
@ -195,7 +195,7 @@ impl Vim {
let count = Vim::take_count(cx).unwrap_or(1) as u32;
Vim::take_forced_motion(cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let mut ranges = Vec::new();
let mut cursor_positions = Vec::new();
let snapshot = editor.buffer().read(cx).snapshot(cx);

View file

@ -22,7 +22,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
@ -82,7 +82,7 @@ impl Vim {
selection.collapse_to(cursor, selection.goal)
});
});
editor.refresh_inline_completion(true, false, window, cx);
editor.refresh_edit_prediction(true, false, window, cx);
});
});
}
@ -96,7 +96,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
// Emulates behavior in vim where if we expanded backwards to include a newline
@ -169,7 +169,7 @@ impl Vim {
selection.collapse_to(cursor, selection.goal)
});
});
editor.refresh_inline_completion(true, false, window, cx);
editor.refresh_edit_prediction(true, false, window, cx);
});
});
}

View file

@ -53,7 +53,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.store_visual_marks(window, cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let mut edits = Vec::new();
let mut new_anchors = Vec::new();

View file

@ -19,7 +19,7 @@ use crate::{
impl Vim {
pub fn create_mark(&mut self, text: Arc<str>, window: &mut Window, cx: &mut Context<Self>) {
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let anchors = editor
.selections
.disjoint_anchors()
@ -49,7 +49,7 @@ impl Vim {
let mut ends = vec![];
let mut reversed = vec![];
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let (map, selections) = editor.selections.all_display(cx);
for selection in selections {
let end = movement::saturating_left(&map, selection.end);
@ -190,7 +190,7 @@ impl Vim {
self.pop_operator(window, cx);
}
let mark = self
.update_editor(window, cx, |vim, editor, window, cx| {
.update_editor(cx, |vim, editor, cx| {
vim.get_mark(&text, editor, window, cx)
})
.flatten();
@ -209,7 +209,7 @@ impl Vim {
let Some(mut anchors) = anchors else { return };
self.update_editor(window, cx, |_, editor, _, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.create_nav_history_entry(cx);
});
let is_active_operator = self.active_operator().is_some();
@ -231,7 +231,7 @@ impl Vim {
|| self.mode == Mode::VisualLine
|| self.mode == Mode::VisualBlock;
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let map = editor.snapshot(window, cx);
let mut ranges: Vec<Range<Anchor>> = Vec::new();
for mut anchor in anchors {

View file

@ -32,7 +32,7 @@ impl Vim {
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
@ -236,7 +236,7 @@ impl Vim {
) {
self.stop_recording(cx);
let selected_register = self.selected_register.take();
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
@ -273,7 +273,7 @@ impl Vim {
) {
self.stop_recording(cx);
let selected_register = self.selected_register.take();
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);

View file

@ -97,7 +97,7 @@ impl Vim {
let amount = by(Vim::take_count(cx).map(|c| c as f32));
Vim::take_forced_motion(cx);
self.exit_temporary_normal(window, cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
scroll_editor(editor, move_cursor, &amount, window, cx)
});
}

View file

@ -251,7 +251,7 @@ impl Vim {
// If the active editor has changed during a search, don't panic.
if prior_selections.iter().any(|s| {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
!s.start
.is_valid(&editor.snapshot(window, cx).buffer_snapshot)
})
@ -457,7 +457,7 @@ impl Vim {
else {
return;
};
if let Some(result) = self.update_editor(window, cx, |vim, editor, window, cx| {
if let Some(result) = self.update_editor(cx, |vim, editor, cx| {
let range = action.range.buffer_range(vim, editor, window, cx)?;
let snapshot = &editor.snapshot(window, cx).buffer_snapshot;
let end_point = Point::new(range.end.0, snapshot.line_len(range.end));

View file

@ -45,7 +45,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.store_visual_marks(window, cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
editor.set_clip_at_line_ends(false, cx);
editor.transact(window, cx, |editor, window, cx| {
let text_layout_details = editor.text_layout_details(window);

View file

@ -14,7 +14,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
let mut selection_starts: HashMap<_, _> = Default::default();
@ -51,7 +51,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let mut original_positions: HashMap<_, _> = Default::default();
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {

View file

@ -25,7 +25,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
@ -70,7 +70,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
let mut start_positions: HashMap<_, _> = Default::default();

View file

@ -49,7 +49,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
let map = editor.snapshot(window, cx);
@ -94,7 +94,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
let map = editor.snapshot(window, cx);
@ -148,7 +148,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
editor.set_clip_at_line_ends(false, cx);
let mut selection = editor.selections.newest_display(cx);
let snapshot = editor.snapshot(window, cx);
@ -167,7 +167,7 @@ impl Vim {
pub fn exchange_visual(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.stop_recording(cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let selection = editor.selections.newest_anchor();
let new_range = selection.start..selection.end;
let snapshot = editor.snapshot(window, cx);
@ -178,7 +178,7 @@ impl Vim {
pub fn clear_exchange(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, _, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.clear_background_highlights::<VimExchange>(cx);
});
self.clear_operator(window, cx);
@ -193,7 +193,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
editor.set_clip_at_line_ends(false, cx);
let text_layout_details = editor.text_layout_details(window);
let mut selection = editor.selections.newest_display(cx);

View file

@ -18,7 +18,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
Vim::take_count(cx);
Vim::take_forced_motion(cx);
vim.store_visual_marks(window, cx);
vim.update_editor(window, cx, |vim, editor, window, cx| {
vim.update_editor(cx, |vim, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let mut positions = vim.save_selection_starts(editor, cx);
editor.rewrap_impl(
@ -55,7 +55,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
let mut selection_starts: HashMap<_, _> = Default::default();
@ -100,7 +100,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let mut original_positions: HashMap<_, _> = Default::default();
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {

View file

@ -29,7 +29,7 @@ impl Vim {
let count = Vim::take_count(cx);
let forced_motion = Vim::take_forced_motion(cx);
let mode = self.mode;
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
@ -140,7 +140,7 @@ impl Vim {
};
let surround = pair.end != *text;
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
@ -228,7 +228,7 @@ impl Vim {
) {
if let Some(will_replace_pair) = object_to_bracket_pair(target) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
@ -344,7 +344,7 @@ impl Vim {
) -> bool {
let mut valid = false;
if let Some(pair) = object_to_bracket_pair(object) {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
editor.set_clip_at_line_ends(false, cx);
let (display_map, selections) = editor.selections.all_adjusted_display(cx);

View file

@ -15,6 +15,7 @@ impl VimTestContext {
if cx.has_global::<VimGlobals>() {
return;
}
env_logger::try_init().ok();
cx.update(|cx| {
let settings = SettingsStore::test(cx);
cx.set_global(settings);

View file

@ -765,8 +765,8 @@ impl Vim {
Vim::action(
editor,
cx,
|vim, action: &editor::AcceptEditPrediction, window, cx| {
vim.update_editor(window, cx, |_, editor, window, cx| {
|vim, action: &editor::actions::AcceptEditPrediction, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
editor.accept_edit_prediction(action, window, cx);
});
// In non-insertion modes, predictions will be hidden and instead a jump will be
@ -886,7 +886,7 @@ impl Vim {
if let Some(action) = keystroke_event.action.as_ref() {
// Keystroke is handled by the vim system, so continue forward
if action.name().starts_with("vim::") {
self.update_editor(window, cx, |_, editor, _, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx)
});
return;
@ -948,7 +948,7 @@ impl Vim {
anchor,
is_deactivate,
} => {
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let mark = if *is_deactivate {
"\"".to_string()
} else {
@ -1011,7 +1011,7 @@ impl Vim {
if mode == Mode::Normal || mode != last_mode {
self.current_tx.take();
self.current_anchor.take();
self.update_editor(window, cx, |_, editor, _, _| {
self.update_editor(cx, |_, editor, _| {
editor.clear_selection_drag_state();
});
}
@ -1027,7 +1027,7 @@ impl Vim {
&& self.mode != self.last_mode
&& (self.mode == Mode::Insert || self.last_mode == Mode::Insert)
{
self.update_editor(window, cx, |vim, editor, _, cx| {
self.update_editor(cx, |vim, editor, cx| {
let is_relative = vim.mode != Mode::Insert;
editor.set_relative_line_number(Some(is_relative), cx)
});
@ -1042,7 +1042,7 @@ impl Vim {
}
// Adjust selections
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
if last_mode != Mode::VisualBlock && last_mode.is_visual() && mode == Mode::VisualBlock
{
vim.visual_block_motion(true, editor, window, cx, |_, point, goal| {
@ -1253,7 +1253,7 @@ impl Vim {
if preserve_selection {
self.switch_mode(Mode::Visual, true, window, cx);
} else {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.set_clip_at_line_ends(false, cx);
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|_, selection| {
@ -1271,18 +1271,18 @@ impl Vim {
if let Some(old_vim) = Vim::globals(cx).focused_vim() {
if old_vim.entity_id() != cx.entity().entity_id() {
old_vim.update(cx, |vim, cx| {
vim.update_editor(window, cx, |_, editor, _, cx| {
vim.update_editor(cx, |_, editor, cx| {
editor.set_relative_line_number(None, cx)
});
});
self.update_editor(window, cx, |vim, editor, _, cx| {
self.update_editor(cx, |vim, editor, cx| {
let is_relative = vim.mode != Mode::Insert;
editor.set_relative_line_number(Some(is_relative), cx)
});
}
} else {
self.update_editor(window, cx, |vim, editor, _, cx| {
self.update_editor(cx, |vim, editor, cx| {
let is_relative = vim.mode != Mode::Insert;
editor.set_relative_line_number(Some(is_relative), cx)
});
@ -1295,35 +1295,30 @@ impl Vim {
self.stop_recording_immediately(NormalBefore.boxed_clone(), cx);
self.store_visual_marks(window, cx);
self.clear_operator(window, cx);
self.update_editor(window, cx, |vim, editor, _, cx| {
self.update_editor(cx, |vim, editor, cx| {
if vim.cursor_shape(cx) == CursorShape::Block {
editor.set_cursor_shape(CursorShape::Hollow, cx);
}
});
}
fn cursor_shape_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.update_editor(window, cx, |vim, editor, _, cx| {
fn cursor_shape_changed(&mut self, _: &mut Window, cx: &mut Context<Self>) {
self.update_editor(cx, |vim, editor, cx| {
editor.set_cursor_shape(vim.cursor_shape(cx), cx);
});
}
fn update_editor<S>(
&mut self,
window: &mut Window,
cx: &mut Context<Self>,
update: impl FnOnce(&mut Self, &mut Editor, &mut Window, &mut Context<Editor>) -> S,
update: impl FnOnce(&mut Self, &mut Editor, &mut Context<Editor>) -> S,
) -> Option<S> {
let editor = self.editor.upgrade()?;
Some(editor.update(cx, |editor, cx| update(self, editor, window, cx)))
Some(editor.update(cx, |editor, cx| update(self, editor, cx)))
}
fn editor_selections(
&mut self,
window: &mut Window,
cx: &mut Context<Self>,
) -> Vec<Range<Anchor>> {
self.update_editor(window, cx, |_, editor, _, _| {
fn editor_selections(&mut self, _: &mut Window, cx: &mut Context<Self>) -> Vec<Range<Anchor>> {
self.update_editor(cx, |_, editor, _| {
editor
.selections
.disjoint_anchors()
@ -1339,7 +1334,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) -> Option<String> {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let selection = editor.selections.newest::<usize>(cx);
let snapshot = &editor.snapshot(window, cx).buffer_snapshot;
@ -1528,7 +1523,7 @@ impl Vim {
) {
match self.mode {
Mode::VisualLine | Mode::VisualBlock | Mode::Visual => {
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let original_mode = vim.undo_modes.get(transaction_id);
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
match original_mode {
@ -1559,7 +1554,7 @@ impl Vim {
self.switch_mode(Mode::Normal, true, window, cx)
}
Mode::Normal => {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.move_with(|map, selection| {
selection
@ -1586,7 +1581,7 @@ impl Vim {
self.current_anchor = Some(newest);
} else if self.current_anchor.as_ref().unwrap() != &newest {
if let Some(tx_id) = self.current_tx.take() {
self.update_editor(window, cx, |_, editor, _, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.group_until_transaction(tx_id, cx)
});
}
@ -1733,7 +1728,7 @@ impl Vim {
}
Some(Operator::Register) => match self.mode {
Mode::Insert => {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
if let Some(register) = Vim::update_globals(cx, |globals, cx| {
globals.read_register(text.chars().next(), Some(editor), cx)
}) {
@ -1759,7 +1754,7 @@ impl Vim {
}
if self.mode == Mode::Normal {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.accept_edit_prediction(
&editor::actions::AcceptEditPrediction {},
window,
@ -1772,7 +1767,7 @@ impl Vim {
}
fn sync_vim_settings(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
editor.set_cursor_shape(vim.cursor_shape(cx), cx);
editor.set_clip_at_line_ends(vim.clip_at_line_ends(), cx);
editor.set_collapse_matches(true);
@ -1780,11 +1775,11 @@ impl Vim {
editor.set_autoindent(vim.should_autoindent());
editor.selections.line_mode = matches!(vim.mode, Mode::VisualLine);
let hide_inline_completions = match vim.mode {
let hide_edit_predictions = match vim.mode {
Mode::Insert | Mode::Replace => false,
_ => true,
};
editor.set_inline_completions_hidden_for_vim_mode(hide_inline_completions, window, cx);
editor.set_edit_predictions_hidden_for_vim_mode(hide_edit_predictions, window, cx);
});
cx.notify()
}

View file

@ -104,7 +104,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
for _ in 0..count {
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
editor.select_larger_syntax_node(&Default::default(), window, cx);
});
}
@ -117,7 +117,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
let count = Vim::take_count(cx).unwrap_or(1);
Vim::take_forced_motion(cx);
for _ in 0..count {
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
editor.select_smaller_syntax_node(&Default::default(), window, cx);
});
}
@ -129,7 +129,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
return;
};
let marks = vim
.update_editor(window, cx, |vim, editor, window, cx| {
.update_editor(cx, |vim, editor, cx| {
vim.get_mark("<", editor, window, cx)
.zip(vim.get_mark(">", editor, window, cx))
})
@ -148,7 +148,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
vim.create_visual_marks(vim.mode, window, cx);
}
vim.update_editor(window, cx, |_, editor, window, cx| {
vim.update_editor(cx, |_, editor, cx| {
editor.set_clip_at_line_ends(false, cx);
editor.change_selections(Default::default(), window, cx, |s| {
let map = s.display_map();
@ -189,7 +189,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let text_layout_details = editor.text_layout_details(window);
if vim.mode == Mode::VisualBlock
&& !matches!(
@ -397,7 +397,7 @@ impl Vim {
self.switch_mode(target_mode, true, window, cx);
}
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| {
let mut mut_selection = selection.clone();
@ -475,7 +475,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.split_selection_into_lines(&Default::default(), window, cx);
editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| {
@ -493,7 +493,7 @@ impl Vim {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.split_selection_into_lines(&Default::default(), window, cx);
editor.change_selections(Default::default(), window, cx, |s| {
s.move_cursors_with(|map, cursor, _| {
@ -517,7 +517,7 @@ impl Vim {
}
pub fn other_end(&mut self, _: &OtherEnd, window: &mut Window, cx: &mut Context<Self>) {
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|_, selection| {
selection.reversed = !selection.reversed;
@ -533,7 +533,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
let mode = self.mode;
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|_, selection| {
selection.reversed = !selection.reversed;
@ -547,7 +547,7 @@ impl Vim {
pub fn visual_delete(&mut self, line_mode: bool, window: &mut Window, cx: &mut Context<Self>) {
self.store_visual_marks(window, cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let mut original_columns: HashMap<_, _> = Default::default();
let line_mode = line_mode || editor.selections.line_mode;
editor.selections.line_mode = false;
@ -631,7 +631,7 @@ impl Vim {
pub fn visual_yank(&mut self, line_mode: bool, window: &mut Window, cx: &mut Context<Self>) {
self.store_visual_marks(window, cx);
self.update_editor(window, cx, |vim, editor, window, cx| {
self.update_editor(cx, |vim, editor, cx| {
let line_mode = line_mode || editor.selections.line_mode;
// For visual line mode, adjust selections to avoid yanking the next line when on \n
@ -679,7 +679,7 @@ impl Vim {
cx: &mut Context<Self>,
) {
self.stop_recording(cx);
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.transact(window, cx, |editor, window, cx| {
let (display_map, selections) = editor.selections.all_adjusted_display(cx);
@ -722,7 +722,7 @@ impl Vim {
Vim::take_forced_motion(cx);
let count =
Vim::take_count(cx).unwrap_or_else(|| if self.mode.is_visual() { 1 } else { 2 });
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
editor.set_clip_at_line_ends(false, cx);
for _ in 0..count {
if editor
@ -745,7 +745,7 @@ impl Vim {
Vim::take_forced_motion(cx);
let count =
Vim::take_count(cx).unwrap_or_else(|| if self.mode.is_visual() { 1 } else { 2 });
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
for _ in 0..count {
if editor
.select_previous(&Default::default(), window, cx)
@ -773,7 +773,7 @@ impl Vim {
let mut start_selection = 0usize;
let mut end_selection = 0usize;
self.update_editor(window, cx, |_, editor, _, _| {
self.update_editor(cx, |_, editor, _| {
editor.set_collapse_matches(false);
});
if vim_is_normal {
@ -791,7 +791,7 @@ impl Vim {
}
});
}
self.update_editor(window, cx, |_, editor, _, cx| {
self.update_editor(cx, |_, editor, cx| {
let latest = editor.selections.newest::<usize>(cx);
start_selection = latest.start;
end_selection = latest.end;
@ -812,7 +812,7 @@ impl Vim {
self.stop_replaying(cx);
return;
}
self.update_editor(window, cx, |_, editor, window, cx| {
self.update_editor(cx, |_, editor, cx| {
let latest = editor.selections.newest::<usize>(cx);
if vim_is_normal {
start_selection = latest.start;