Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
savente93 committed Oct 1, 2023
1 parent 21e2b4d commit 9713aa3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 173 deletions.
70 changes: 18 additions & 52 deletions src/edit_mode/hx/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,22 @@ where
let _ = input.next();
Some(Command::Undo)
}
Some('U') => {
let _ = input.next();
Some(Command::Redo)
}
Some('c') => {
let _ = input.next();
Some(Command::Change)
}
Some('x') => {
let _ = input.next();
Some(Command::DeleteChar)
}
Some('r') => {
let _ = input.next();
match input.next() {
Some(c) => Some(Command::ReplaceChar(*c)),
None => Some(Command::Incomplete),
}
}
Some('s') => {
let _ = input.next();
Some(Command::SubstituteCharWithInsert)
Some(Command::SelectLine)
}
Some('?') => {
let _ = input.next();
Some(Command::HistorySearch)
}
Some('C') => {
let _ = input.next();
Some(Command::ChangeToLineEnd)
}
Some('D') => {
let _ = input.next();
Some(Command::DeleteToEnd)
}
Some('I') => {
let _ = input.next();
Some(Command::PrependToStart)
Expand All @@ -70,17 +55,17 @@ where
let _ = input.next();
Some(Command::AppendToEnd)
}
Some('S') => {
let _ = input.next();
Some(Command::RewriteCurrentLine)
}
Some('~') => {
let _ = input.next();
Some(Command::Switchcase)
}
Some('-') => {
let _ = input.next();
Some(Command::TrimSelection)
}
Some('.') => {
let _ = input.next();
Some(Command::RepeatLastAction)
Some(Command::RepeatLastInsertion)
}
_ => None,
}
Expand All @@ -92,21 +77,20 @@ pub enum Command {
Delete,
DeleteChar,
ReplaceChar(char),
SubstituteCharWithInsert,
PasteAfter,
PasteBefore,
EnterHxAppend,
EnterHxInsert,
Undo,
ChangeToLineEnd,
DeleteToEnd,
Redo,
SelectLine,
TrimSelection,
AppendToEnd,
PrependToStart,
RewriteCurrentLine,
Change,
HistorySearch,
Switchcase,
RepeatLastAction,
RepeatLastInsertion,
}

impl Command {
Expand All @@ -129,24 +113,23 @@ impl Command {
Self::PasteAfter => vec![ReedlineOption::Edit(EditCommand::PasteCutBufferAfter)],
Self::PasteBefore => vec![ReedlineOption::Edit(EditCommand::PasteCutBufferBefore)],
Self::Undo => vec![ReedlineOption::Edit(EditCommand::Undo)],
Self::ChangeToLineEnd => vec![ReedlineOption::Edit(EditCommand::ClearToLineEnd)],
Self::DeleteToEnd => vec![ReedlineOption::Edit(EditCommand::CutToLineEnd)],
Self::AppendToEnd => vec![ReedlineOption::Edit(EditCommand::MoveToLineEnd)],
Self::PrependToStart => vec![ReedlineOption::Edit(EditCommand::MoveToLineStart)],
Self::RewriteCurrentLine => vec![ReedlineOption::Edit(EditCommand::CutCurrentLine)],
Self::DeleteChar => vec![ReedlineOption::Edit(EditCommand::CutChar)],
Self::ReplaceChar(c) => {
vec![ReedlineOption::Edit(EditCommand::ReplaceChar(*c))]
}
Self::SubstituteCharWithInsert => vec![ReedlineOption::Edit(EditCommand::CutChar)],
Self::HistorySearch => vec![ReedlineOption::Event(ReedlineEvent::SearchHistory)],
Self::Switchcase => vec![ReedlineOption::Edit(EditCommand::SwitchcaseChar)],
// Mark a command as incomplete whenever a motion is required to finish the command
Self::Delete | Self::Change | Self::Incomplete => vec![ReedlineOption::Incomplete],
Command::RepeatLastAction => match &hx_state.previous {
Self::RepeatLastInsertion => match &hx_state.previous {
Some(event) => vec![ReedlineOption::Event(event.clone())],
None => vec![],
},
Self::Redo => todo!(),
Self::SelectLine => todo!(),
Self::TrimSelection => todo!(),
}
}

Expand Down Expand Up @@ -194,14 +177,6 @@ impl Command {
Motion::Right => Some(vec![ReedlineOption::Edit(EditCommand::Delete)]),
Motion::Up => None,
Motion::Down => None,
Motion::ReplayCharSearch => hx_state
.last_char_search
.as_ref()
.map(|char_search| vec![ReedlineOption::Edit(char_search.to_cut())]),
Motion::ReverseCharSearch => hx_state
.last_char_search
.as_ref()
.map(|char_search| vec![ReedlineOption::Edit(char_search.reverse().to_cut())]),
},
Self::Change => {
let op = match motion {
Expand Down Expand Up @@ -251,15 +226,6 @@ impl Command {
Motion::Right => Some(vec![ReedlineOption::Edit(EditCommand::Delete)]),
Motion::Up => None,
Motion::Down => None,
Motion::ReplayCharSearch => hx_state
.last_char_search
.as_ref()
.map(|char_search| vec![ReedlineOption::Edit(char_search.to_cut())]),
Motion::ReverseCharSearch => {
hx_state.last_char_search.as_ref().map(|char_search| {
vec![ReedlineOption::Edit(char_search.reverse().to_cut())]
})
}
};
// Semihack: Append `Repaint` to ensure the mode change gets displayed
op.map(|mut vec| {
Expand Down
21 changes: 6 additions & 15 deletions src/edit_mode/hx/hx_keybindings.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
use crossterm::event::{KeyCode, KeyModifiers};

use crate::{
edit_mode::{
keybindings::{
add_common_control_bindings, add_common_edit_bindings, add_common_navigation_bindings,
edit_bind,
},
Keybindings,
use crate::edit_mode::{
keybindings::{
add_common_control_bindings, add_common_edit_bindings, add_common_navigation_bindings,
},
EditCommand,
Keybindings,
};

/// Default hx normal keybindings
/// Default Hx normal keybindings
pub fn default_hx_normal_keybindings() -> Keybindings {
let mut kb = Keybindings::new();
use EditCommand as EC;
use KeyCode as KC;
use KeyModifiers as KM;

add_common_control_bindings(&mut kb);
add_common_navigation_bindings(&mut kb);
kb
}

/// Default Vi insert keybindings
/// Default Hx insert keybindings
pub fn default_hx_insert_keybindings() -> Keybindings {
let mut kb = Keybindings::new();

Expand Down
1 change: 0 additions & 1 deletion src/edit_mode/hx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub struct Hx {
normal_keybindings: Keybindings,
mode: HxMode,
previous: Option<ReedlineEvent>,
// last f, F, t, T motion for ; and ,
last_char_search: Option<HxCharSearch>,
}

Expand Down
32 changes: 0 additions & 32 deletions src/edit_mode/hx/motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ where
let _ = input.next();
ParseResult::Valid(Motion::NextBigWordEnd)
}
Some('0' | '^') => {
let _ = input.next();
ParseResult::Valid(Motion::Start)
}
Some('$') => {
let _ = input.next();
ParseResult::Valid(Motion::End)
}
Some('f') => {
let _ = input.next();
match input.peek() {
Expand Down Expand Up @@ -100,14 +92,6 @@ where
None => ParseResult::Incomplete,
}
}
Some(';') => {
let _ = input.next();
ParseResult::Valid(Motion::ReplayCharSearch)
}
Some(',') => {
let _ = input.next();
ParseResult::Valid(Motion::ReverseCharSearch)
}
ch if ch == command_char.as_ref().as_ref() && command_char.is_some() => {
let _ = input.next();
ParseResult::Valid(Motion::Line)
Expand Down Expand Up @@ -136,8 +120,6 @@ pub enum Motion {
RightBefore(char),
LeftUntil(char),
LeftBefore(char),
ReplayCharSearch,
ReverseCharSearch,
}

impl Motion {
Expand Down Expand Up @@ -185,20 +167,6 @@ impl Motion {
hx_state.last_char_search = Some(HxCharSearch::TillLeft(*ch));
vec![ReedlineOption::Edit(EditCommand::MoveLeftBefore(*ch))]
}
Motion::ReplayCharSearch => {
if let Some(char_search) = hx_state.last_char_search.as_ref() {
vec![ReedlineOption::Edit(char_search.to_move())]
} else {
vec![]
}
}
Motion::ReverseCharSearch => {
if let Some(char_search) = hx_state.last_char_search.as_ref() {
vec![ReedlineOption::Edit(char_search.reverse().to_move())]
} else {
vec![]
}
}
}
}
}
Expand Down
Loading

0 comments on commit 9713aa3

Please sign in to comment.