diff --git a/src/action.rs b/src/action.rs index 66495a6..05dabfe 100644 --- a/src/action.rs +++ b/src/action.rs @@ -416,6 +416,10 @@ impl TryFrom<&str> for BufferAction { "find_till_null" => Ok(FindTillNull), "find_till_ff" => Ok(FindTillFF), + "extend_till_mark" => Ok(ExtendTillMark), + "extend_till_null" => Ok(ExtendTillNull), + "extend_till_ff" => Ok(ExtendTillFF), + "inspect_selection" => Ok(InspectSelection), "inspect_selection_color" => Ok(InspectSelectionColor), @@ -443,6 +447,11 @@ pub enum CursorAction { GotoFileStart, GotoFileEnd, + ExtendLineStart, + ExtendLineEnd, + ExtendFileStart, + ExtendFileEnd, + MoveNextWordStart, MoveNextWordEnd, MovePreviousWordStart, @@ -476,6 +485,11 @@ impl CursorAction { GotoFileStart => true, GotoFileEnd => true, + ExtendLineStart => true, + ExtendLineEnd => true, + ExtendFileStart => true, + ExtendFileEnd => true, + MoveNextWordStart => true, MoveNextWordEnd => true, MovePreviousWordStart => true, @@ -510,6 +524,11 @@ impl From for &str { GotoFileStart => "goto_file_start", GotoFileEnd => "goto_file_end", + ExtendLineStart => "extend_line_start", + ExtendLineEnd => "extend_line_end", + ExtendFileStart => "extend_file_start", + ExtendFileEnd => "extend_file_end", + MoveNextWordStart => "move_next_word_start", MoveNextWordEnd => "move_next_word_end", MovePreviousWordStart => "move_previous_word_start", @@ -552,6 +571,11 @@ impl TryFrom<&str> for CursorAction { "goto_file_start" => Ok(GotoFileStart), "goto_file_end" => Ok(GotoFileEnd), + "extend_line_start" => Ok(ExtendLineStart), + "extend_line_end" => Ok(ExtendLineEnd), + "extend_file_start" => Ok(ExtendFileStart), + "extend_file_end" => Ok(ExtendFileEnd), + "move_next_word_start" => Ok(MoveNextWordStart), "move_next_word_end" => Ok(MoveNextWordEnd), "move_previous_word_start" => Ok(MovePreviousWordStart), diff --git a/src/config/default.rs b/src/config/default.rs index cbe13a3..881808c 100644 --- a/src/config/default.rs +++ b/src/config/default.rs @@ -163,6 +163,8 @@ impl Default for Config { (keypress("j"), ExtendByteLeft.into()), (keypress("l"), ExtendByteRight.into()), + (keypress("G"), ExtendFileEnd.into()), + (keypress("up"), ExtendByteUp.into()), (keypress("down"), ExtendByteDown.into()), (keypress("left"), ExtendByteLeft.into()), @@ -220,6 +222,12 @@ impl Default for Config { (keypress("C- "), InspectSelection.into()), (keypress("A- "), InspectSelectionColor.into()), ].into()), + (Some(PartialAction::Goto), [ + (keypress("j"), ExtendLineStart.into()), + (keypress("l"), ExtendLineEnd.into()), + + (keypress("g"), ExtendFileStart.into()), + ].into()), (Some(PartialAction::View), [ (keypress("z"), AlignViewCenter.into()), (keypress("b"), AlignViewBottom.into()), diff --git a/src/cursor/actions.rs b/src/cursor/actions.rs index 68fb3e7..be7adf8 100644 --- a/src/cursor/actions.rs +++ b/src/cursor/actions.rs @@ -23,6 +23,11 @@ impl Cursor { CursorAction::GotoFileStart => self.goto_file_start(), CursorAction::GotoFileEnd => self.goto_file_end(max_contents_index), + CursorAction::ExtendLineStart => self.extend_line_start(), + CursorAction::ExtendLineEnd => self.extend_line_end(max_contents_index), + CursorAction::ExtendFileStart => self.extend_file_start(), + CursorAction::ExtendFileEnd => self.extend_file_end(max_contents_index), + CursorAction::MoveNextWordStart => self.move_next_word_start(max_contents_index), CursorAction::MoveNextWordEnd => self.move_next_word_end(max_contents_index), CursorAction::MovePreviousWordStart => self.move_previous_word_start(), @@ -89,27 +94,43 @@ impl Cursor { } pub const fn goto_line_start(&mut self) { - self.head -= self.head % BYTES_PER_LINE; + self.extend_line_start(); self.collapse(); } pub fn goto_line_end(&mut self, max: usize) { - self.head = min( - self.head + BYTES_PER_LINE - 1 - (self.head % BYTES_PER_LINE), - max - ); + self.extend_line_end(max); self.collapse(); } pub const fn goto_file_start(&mut self) { - self.head %= BYTES_PER_LINE; + self.extend_file_start(); self.collapse(); } pub const fn goto_file_end(&mut self, max: usize) { + self.extend_file_end(max); + self.collapse(); + } + + pub const fn extend_line_start(&mut self) { + self.head -= self.head % BYTES_PER_LINE; + } + + pub fn extend_line_end(&mut self, max: usize) { + self.head = min( + self.head + BYTES_PER_LINE - 1 - (self.head % BYTES_PER_LINE), + max + ); + } + + pub const fn extend_file_start(&mut self) { + self.head %= BYTES_PER_LINE; + } + + pub const fn extend_file_end(&mut self, max: usize) { self.head += previous_multiple_of(BYTES_PER_LINE, max + 1 - self.head); - self.collapse(); } pub fn move_next_word_start(&mut self, max: usize) { diff --git a/src/main.rs b/src/main.rs index 7d3f820..45ab635 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,8 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; // - update showcase // - fix scroll clamping // - inspector translations for varint -// - repeat in select mode doesnt work right +// - repeated actions may only be cursor actions +// - shouldn't crash // - gg/G in select mode // - gl/gj in select mode // - scrolling in select mode