Closes #ISSUE

Release Notes:

- vim: Added gq/gw for rewrapping lines
This commit is contained in:
Conrad Irwin 2024-09-20 13:02:39 -06:00 committed by GitHub
parent 7dac5594cd
commit 45388805ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 177 additions and 3 deletions

View file

@ -168,6 +168,7 @@ impl Vim {
Some(Operator::Yank) => self.yank_motion(motion, times, cx),
Some(Operator::AddSurrounds { target: None }) => {}
Some(Operator::Indent) => self.indent_motion(motion, times, IndentDirection::In, cx),
Some(Operator::Rewrap) => self.rewrap_motion(motion, times, cx),
Some(Operator::Outdent) => self.indent_motion(motion, times, IndentDirection::Out, cx),
Some(Operator::Lowercase) => {
self.change_case_motion(motion, times, CaseTarget::Lowercase, cx)
@ -199,6 +200,7 @@ impl Vim {
Some(Operator::Outdent) => {
self.indent_object(object, around, IndentDirection::Out, cx)
}
Some(Operator::Rewrap) => self.rewrap_object(object, around, cx),
Some(Operator::Lowercase) => {
self.change_case_object(object, around, CaseTarget::Lowercase, cx)
}
@ -478,8 +480,9 @@ impl Vim {
}
#[cfg(test)]
mod test {
use gpui::{KeyBinding, TestAppContext};
use gpui::{KeyBinding, TestAppContext, UpdateGlobal};
use indoc::indoc;
use language::language_settings::AllLanguageSettings;
use settings::SettingsStore;
use crate::{
@ -1386,4 +1389,29 @@ mod test {
cx.simulate_shared_keystrokes("2 0 r - ").await;
cx.shared_state().await.assert_eq("ˇhello world\n");
}
#[gpui::test]
async fn test_gq(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_neovim_option("textwidth=5").await;
cx.update(|cx| {
SettingsStore::update_global(cx, |settings, cx| {
settings.update_user_settings::<AllLanguageSettings>(cx, |settings| {
settings.defaults.preferred_line_length = Some(5);
});
})
});
cx.set_shared_state("ˇth th th th th th\n").await;
cx.simulate_shared_keystrokes("g q q").await;
cx.shared_state().await.assert_eq("th th\nth th\nˇth th\n");
cx.set_shared_state("ˇth th th th th th\nth th th th th th\n")
.await;
cx.simulate_shared_keystrokes("v j g q").await;
cx.shared_state()
.await
.assert_eq("th th\nth th\nth th\nth th\nth th\nˇth th\n");
}
}