Simulate helix line wrapping (#32763)

In helix the `f`, `F`, `t`, `T`, left and right motions wrap lines. I
added that by default.

Release Notes:

- vim: The `use_multiline_find` setting is replaced by binding to the
correct action in the keymap:
    ```
"f": ["vim::PushFindForward", { "before": false, "multiline": true }],
"t": ["vim::PushFindForward", { "before": true, "multiline": true }],
"shift-f": ["vim::PushFindBackward", { "after": false, "multiline": true
}],
"shift-t": ["vim::PushFindBackward", { "after": true, "multiline": true
}],
    ```
- helix: `f`/`t`/`shift-f`/`shift-t`/`h`/`l`/`left`/`right` are now
multiline by default (like helix)
This commit is contained in:
fantacell 2025-06-24 18:51:41 +02:00 committed by GitHub
parent 7be57baef0
commit 95cf153ad7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 60 additions and 104 deletions

View file

@ -435,4 +435,37 @@ mod test {
// Mode::HelixNormal,
// );
// }
#[gpui::test]
async fn test_f_and_t(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
cx.set_state(
indoc! {"
The quˇick brown
fox jumps over
the lazy dog."},
Mode::HelixNormal,
);
cx.simulate_keystrokes("f z");
cx.assert_state(
indoc! {"
The qu«ick brown
fox jumps over
the lazˇ»y dog."},
Mode::HelixNormal,
);
cx.simulate_keystrokes("2 T r");
cx.assert_state(
indoc! {"
The quick br«ˇown
fox jumps over
the laz»y dog."},
Mode::HelixNormal,
);
}
}

View file

@ -1532,90 +1532,6 @@ mod test {
}
}
#[gpui::test]
async fn test_f_and_t_multiline(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
cx.update_global(|store: &mut SettingsStore, cx| {
store.update_user_settings::<VimSettings>(cx, |s| {
s.use_multiline_find = Some(true);
});
});
cx.assert_binding(
"f l",
indoc! {"
ˇfunction print() {
console.log('ok')
}
"},
Mode::Normal,
indoc! {"
function print() {
consoˇle.log('ok')
}
"},
Mode::Normal,
);
cx.assert_binding(
"t l",
indoc! {"
ˇfunction print() {
console.log('ok')
}
"},
Mode::Normal,
indoc! {"
function print() {
consˇole.log('ok')
}
"},
Mode::Normal,
);
}
#[gpui::test]
async fn test_capital_f_and_capital_t_multiline(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;
cx.update_global(|store: &mut SettingsStore, cx| {
store.update_user_settings::<VimSettings>(cx, |s| {
s.use_multiline_find = Some(true);
});
});
cx.assert_binding(
"shift-f p",
indoc! {"
function print() {
console.ˇlog('ok')
}
"},
Mode::Normal,
indoc! {"
function ˇprint() {
console.log('ok')
}
"},
Mode::Normal,
);
cx.assert_binding(
"shift-t p",
indoc! {"
function print() {
console.ˇlog('ok')
}
"},
Mode::Normal,
indoc! {"
function pˇrint() {
console.log('ok')
}
"},
Mode::Normal,
);
}
#[gpui::test]
async fn test_f_and_t_smartcase(cx: &mut gpui::TestAppContext) {
let mut cx = VimTestContext::new(cx, true).await;

View file

@ -86,9 +86,11 @@ pub enum Operator {
},
FindForward {
before: bool,
multiline: bool,
},
FindBackward {
after: bool,
multiline: bool,
},
Sneak {
first_char: Option<char>,
@ -994,12 +996,12 @@ impl Operator {
Operator::Replace => "r",
Operator::Digraph { .. } => "^K",
Operator::Literal { .. } => "^V",
Operator::FindForward { before: false } => "f",
Operator::FindForward { before: true } => "t",
Operator::FindForward { before: false, .. } => "f",
Operator::FindForward { before: true, .. } => "t",
Operator::Sneak { .. } => "s",
Operator::SneakBackward { .. } => "S",
Operator::FindBackward { after: false } => "F",
Operator::FindBackward { after: true } => "T",
Operator::FindBackward { after: false, .. } => "F",
Operator::FindBackward { after: true, .. } => "T",
Operator::AddSurrounds { .. } => "ys",
Operator::ChangeSurrounds { .. } => "cs",
Operator::DeleteSurrounds => "ds",

View file

@ -72,6 +72,7 @@ struct PushObject {
#[serde(deny_unknown_fields)]
struct PushFindForward {
before: bool,
multiline: bool,
}
#[derive(Clone, Deserialize, JsonSchema, PartialEq, Action)]
@ -79,6 +80,7 @@ struct PushFindForward {
#[serde(deny_unknown_fields)]
struct PushFindBackward {
after: bool,
multiline: bool,
}
#[derive(Clone, Deserialize, JsonSchema, PartialEq, Action)]
@ -500,6 +502,7 @@ impl Vim {
vim.push_operator(
Operator::FindForward {
before: action.before,
multiline: action.multiline,
},
window,
cx,
@ -510,6 +513,7 @@ impl Vim {
vim.push_operator(
Operator::FindBackward {
after: action.after,
multiline: action.multiline,
},
window,
cx,
@ -1513,11 +1517,11 @@ impl Vim {
}
match self.active_operator() {
Some(Operator::FindForward { before }) => {
Some(Operator::FindForward { before, multiline }) => {
let find = Motion::FindForward {
before,
char: text.chars().next().unwrap(),
mode: if VimSettings::get_global(cx).use_multiline_find {
mode: if multiline {
FindRange::MultiLine
} else {
FindRange::SingleLine
@ -1527,11 +1531,11 @@ impl Vim {
Vim::globals(cx).last_find = Some(find.clone());
self.motion(find, window, cx)
}
Some(Operator::FindBackward { after }) => {
Some(Operator::FindBackward { after, multiline }) => {
let find = Motion::FindBackward {
after,
char: text.chars().next().unwrap(),
mode: if VimSettings::get_global(cx).use_multiline_find {
mode: if multiline {
FindRange::MultiLine
} else {
FindRange::SingleLine
@ -1729,7 +1733,6 @@ struct VimSettings {
pub default_mode: Mode,
pub toggle_relative_line_numbers: bool,
pub use_system_clipboard: UseSystemClipboard,
pub use_multiline_find: bool,
pub use_smartcase_find: bool,
pub custom_digraphs: HashMap<String, Arc<str>>,
pub highlight_on_yank_duration: u64,
@ -1741,7 +1744,6 @@ struct VimSettingsContent {
pub default_mode: Option<ModeContent>,
pub toggle_relative_line_numbers: Option<bool>,
pub use_system_clipboard: Option<UseSystemClipboard>,
pub use_multiline_find: Option<bool>,
pub use_smartcase_find: Option<bool>,
pub custom_digraphs: Option<HashMap<String, Arc<str>>>,
pub highlight_on_yank_duration: Option<u64>,
@ -1794,9 +1796,6 @@ impl Settings for VimSettings {
use_system_clipboard: settings
.use_system_clipboard
.ok_or_else(Self::missing_default)?,
use_multiline_find: settings
.use_multiline_find
.ok_or_else(Self::missing_default)?,
use_smartcase_find: settings
.use_smartcase_find
.ok_or_else(Self::missing_default)?,