From d745d251d68246c1348b127a19e507182c0bdc03 Mon Sep 17 00:00:00 2001 From: Jack Wright Date: Mon, 4 Nov 2024 07:29:58 -0800 Subject: [PATCH 1/3] more work implementing change in word --- Cargo.lock | 2 +- src/edit_mode/vi/command.rs | 28 ++++++++++++++++++---------- src/edit_mode/vi/parser.rs | 6 ++---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a35b5db5..91e68fcc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -691,7 +691,7 @@ dependencies = [ [[package]] name = "reedline" -version = "0.35.0" +version = "0.36.0" dependencies = [ "arboard", "chrono", diff --git a/src/edit_mode/vi/command.rs b/src/edit_mode/vi/command.rs index f00b549b..59a4da1c 100644 --- a/src/edit_mode/vi/command.rs +++ b/src/edit_mode/vi/command.rs @@ -12,11 +12,7 @@ where if let Some('i') = input.peek() { let _ = input.next(); match input.next() { - Some(c) - if is_valid_change_inside_left(c) || is_valid_change_inside_right(c) => - { - Some(Command::DeleteInside(*c)) - } + Some(c) if is_valid_change_inside(c) => Some(Command::DeleteInside(*c)), _ => None, } } else { @@ -48,11 +44,7 @@ where if let Some('i') = input.peek() { let _ = input.next(); match input.next() { - Some(c) - if is_valid_change_inside_left(c) || is_valid_change_inside_right(c) => - { - Some(Command::ChangeInside(*c)) - } + Some(c) if is_valid_change_inside(c) => Some(Command::ChangeInside(*c)), _ => None, } } else { @@ -180,6 +172,12 @@ impl Command { Some(event) => vec![ReedlineOption::Event(event.clone())], None => vec![], }, + Self::ChangeInside('w') => { + vec![ + ReedlineOption::Edit(EditCommand::BackspaceWord), + ReedlineOption::Edit(EditCommand::DeleteWord), + ] + } Self::ChangeInside(left) if is_valid_change_inside_left(left) => { let right = bracket_for(left); vec![ @@ -197,6 +195,12 @@ impl Command { Self::ChangeInside(_) => { vec![] } + Self::DeleteInside('w') => { + vec![ + ReedlineOption::Edit(EditCommand::BackspaceWord), + ReedlineOption::Edit(EditCommand::DeleteWord), + ] + } Self::DeleteInside(left) if is_valid_change_inside_left(left) => { let right = bracket_for(left); vec![ @@ -351,6 +355,10 @@ fn bracket_for(c: &char) -> char { } } +pub(crate) fn is_valid_change_inside(c: &char) -> bool { + *c == 'w' && is_valid_change_inside_left(c) && is_valid_change_inside_right(c) +} + pub(crate) fn is_valid_change_inside_left(c: &char) -> bool { matches!(c, '(' | '[' | '{' | '"' | '\'' | '`' | '<') } diff --git a/src/edit_mode/vi/parser.rs b/src/edit_mode/vi/parser.rs index 0699dbc1..40477970 100644 --- a/src/edit_mode/vi/parser.rs +++ b/src/edit_mode/vi/parser.rs @@ -1,6 +1,4 @@ -use super::command::{ - is_valid_change_inside_left, is_valid_change_inside_right, parse_command, Command, -}; +use super::command::{is_valid_change_inside, parse_command, Command}; use super::motion::{parse_motion, Motion}; use crate::{edit_mode::vi::ViMode, EditCommand, ReedlineEvent, Vi}; use std::iter::Peekable; @@ -110,7 +108,7 @@ impl ParsedViSequence { | (Some(Command::HistorySearch), ParseResult::Incomplete) | (Some(Command::Change), ParseResult::Valid(_)) => Some(ViMode::Insert), (Some(Command::ChangeInside(char)), ParseResult::Incomplete) - if is_valid_change_inside_left(char) || is_valid_change_inside_right(char) => + if is_valid_change_inside(char) => { Some(ViMode::Insert) } From ba310d663907578813fa908863d5ee607315984b Mon Sep 17 00:00:00 2001 From: Jack Wright Date: Mon, 11 Nov 2024 22:58:09 -0800 Subject: [PATCH 2/3] Fixed conditionals --- src/edit_mode/vi/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/edit_mode/vi/command.rs b/src/edit_mode/vi/command.rs index 59a4da1c..069b5bfe 100644 --- a/src/edit_mode/vi/command.rs +++ b/src/edit_mode/vi/command.rs @@ -356,7 +356,7 @@ fn bracket_for(c: &char) -> char { } pub(crate) fn is_valid_change_inside(c: &char) -> bool { - *c == 'w' && is_valid_change_inside_left(c) && is_valid_change_inside_right(c) + *c == 'w' || is_valid_change_inside_left(c) || is_valid_change_inside_right(c) } pub(crate) fn is_valid_change_inside_left(c: &char) -> bool { From 0f18ca1669788767cb4730e01fb12a5bcf6b40ae Mon Sep 17 00:00:00 2001 From: Jack Wright Date: Thu, 14 Nov 2024 18:07:07 -0800 Subject: [PATCH 3/3] fix conflicts --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 91e68fcc..5f8f5f11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -691,7 +691,7 @@ dependencies = [ [[package]] name = "reedline" -version = "0.36.0" +version = "0.37.0" dependencies = [ "arboard", "chrono",