@@ -9,8 +9,8 @@ use helix_core::{
99 object, pos_at_coords,
1010 regex::{self, Regex},
1111 register::Register,
12− search, selection, LineEnding, Position, Range, Rope, RopeGraphemes, RopeSlice, Selection,
13− SmallVec, Tendril, Transaction,
12+ search, selection, surround, textobject, LineEnding, Position, Range, Rope, RopeGraphemes,
13+ RopeSlice, Selection, SmallVec, Tendril, Transaction,
1414};
1515
1616use helix_view::{
@@ -78,7 +78,9 @@ impl<'a> Context<'a> {
7878
7979 #[inline]
8080 pub fn on_next_key_mode(&mut self, map: HashMap<KeyEvent, fn(&mut Context)>) {
81+ let count = self.count;
8182 self.on_next_key(move |cx, event| {
83+ cx.count = count;
8284 cx.editor.autoinfo = None;
8385 if let Some(func) = map.get(&event) {
8486 func(cx);
@@ -3337,24 +3339,6 @@ fn jump_backward(cx: &mut Context) {
33373339 };
33383340}
33393341
3340−fn window_mode(cx: &mut Context) {
3341− cx.on_next_key(move |cx, event| {
3342− if let KeyEvent {
3343− code: KeyCode::Char(ch),
3344− ..
3345− } = event
3346− {
3347− match ch {
3348− 'w' => rotate_view(cx),
3349− 'h' => hsplit(cx),
3350− 'v' => vsplit(cx),
3351− 'q' => wclose(cx),
3352− _ => {}
3353− }
3354− }
3355− })
3356−}
3357−
33583342fn rotate_view(cx: &mut Context) {
33593343 cx.editor.focus_next()
33603344}
@@ -3443,62 +3427,12 @@ fn view_mode(cx: &mut Context) {
34433427 })
34443428}
34453429
3446−fn left_bracket_mode(cx: &mut Context) {
3447− cx.on_next_key(move |cx, event| {
3448− if let KeyEvent {
3449− code: KeyCode::Char(ch),
3450− ..
3451− } = event
3452− {
3453− match ch {
3454− 'd' => goto_prev_diag(cx),
3455− 'D' => goto_first_diag(cx),
3456− _ => (),
3457− }
3458− }
3459− })
3460−}
3461−
3462−fn right_bracket_mode(cx: &mut Context) {
3463− cx.on_next_key(move |cx, event| {
3464− if let KeyEvent {
3465− code: KeyCode::Char(ch),
3466− ..
3467− } = event
3468− {
3469− match ch {
3470− 'd' => goto_next_diag(cx),
3471− 'D' => goto_last_diag(cx),
3472− _ => (),
3473− }
3474− }
3475− })
3430+fn select_textobject_around(cx: &mut Context) {
3431+ select_textobject(cx, textobject::TextObject::Around);
34763432}
34773433
3478−use helix_core::surround;
3479−use helix_core::textobject;
3480−
3481−fn match_mode(cx: &mut Context) {
3482− let count = cx.count;
3483− cx.on_next_key(move |cx, event| {
3484− if let KeyEvent {
3485− code: KeyCode::Char(ch),
3486− ..
3487− } = event
3488− {
3489− // FIXME: count gets reset because of cx.on_next_key()
3490− cx.count = count;
3491− match ch {
3492− 'm' => match_brackets(cx),
3493− 's' => surround_add(cx),
3494− 'r' => surround_replace(cx),
3495− 'd' => surround_delete(cx),
3496− 'a' => select_textobject(cx, textobject::TextObject::Around),
3497− 'i' => select_textobject(cx, textobject::TextObject::Inside),
3498− _ => (),
3499− }
3500− }
3501− })
3434+fn select_textobject_inner(cx: &mut Context) {
3435+ select_textobject(cx, textobject::TextObject::Inside);
35023436}
35033437
35043438fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
@@ -3719,7 +3653,7 @@ mode_info! {
37193653}
37203654
37213655mode_info! {
3722− /// goto mode
3656+ /// goto
37233657 ///
37243658 /// When specified with a count, it will go to that line without entering the mode.
37253659 goto_mode, GOTO_MODE, goto_prehook,
@@ -3750,3 +3684,51 @@ mode_info! {
37503684 /// last accessed file
37513685 "a" => goto_last_accessed_file,
37523686}
3687+
3688+mode_info! {
3689+ /// window
3690+ window_mode, WINDOW_MODE,
3691+ /// rotate
3692+ "w" => rotate_view,
3693+ /// horizontal split
3694+ "h" => hsplit,
3695+ /// vertical split
3696+ "v" => vsplit,
3697+ /// close
3698+ "q" => wclose,
3699+}
3700+
3701+mode_info! {
3702+ /// match
3703+ match_mode, MATCH_MODE,
3704+ /// matching character
3705+ "m" => match_brackets,
3706+ /// surround add
3707+ "s" => surround_add,
3708+ /// surround replace
3709+ "r" => surround_replace,
3710+ /// surround delete
3711+ "d" => surround_delete,
3712+ /// around object
3713+ "a" => select_textobject_around,
3714+ /// inside object
3715+ "i" => select_textobject_inner,
3716+}
3717+
3718+mode_info! {
3719+ /// select to previous
3720+ left_bracket_mode, LEFT_BRACKET_MODE,
3721+ /// previous diagnostic
3722+ "d" => goto_prev_diag,
3723+ /// diagnostic (first)
3724+ "D" => goto_first_diag,
3725+}
3726+
3727+mode_info! {
3728+ /// select to next
3729+ right_bracket_mode, RIGHT_BRACKET_MODE,
3730+ /// diagnostic
3731+ "d" => goto_next_diag,
3732+ /// diagnostic (last)
3733+ "D" => goto_last_diag,
3734+}