From cc0ae065c63e606b94dbc094285c7696713cb02c Mon Sep 17 00:00:00 2001 From: alice pellerin Date: Sat, 25 Apr 2026 18:08:46 -0500 Subject: [PATCH] fix till in select mode --- src/action.rs | 36 ++++++++++++++++--------- src/buffer.rs | 4 +-- src/buffer/actions.rs | 42 ++++++++++++++++++++--------- src/buffer/widget/extra_statuses.rs | 2 +- src/config/default.rs | 16 +++++------ src/main.rs | 1 - 6 files changed, 64 insertions(+), 37 deletions(-) diff --git a/src/action.rs b/src/action.rs index cf707f5..66495a6 100644 --- a/src/action.rs +++ b/src/action.rs @@ -180,9 +180,13 @@ pub enum BufferAction { AlignViewBottom, AlignViewTop, - ExtendToMark, - ExtendToNull, - ExtendToFF, + FindTillMark, + FindTillNull, + FindTillFF, + + ExtendTillMark, + ExtendTillNull, + ExtendTillFF, InspectSelection, InspectSelectionColor, @@ -250,9 +254,13 @@ impl BufferAction { AlignViewBottom => false, AlignViewTop => false, - ExtendToMark => true, - ExtendToNull => true, - ExtendToFF => true, + FindTillMark => true, + FindTillNull => true, + FindTillFF => true, + + ExtendTillMark => true, + ExtendTillNull => true, + ExtendTillFF => true, InspectSelection => true, InspectSelectionColor => true, @@ -321,9 +329,13 @@ impl From for &str { AlignViewBottom => "align_view_bottom", AlignViewTop => "align_view_top", - ExtendToMark => "extend_to_mark", - ExtendToNull => "extend_to_null", - ExtendToFF => "extend_to_ff", + FindTillMark => "find_till_mark", + FindTillNull => "find_till_null", + FindTillFF => "find_till_ff", + + ExtendTillMark => "extend_till_mark", + ExtendTillNull => "extend_till_null", + ExtendTillFF => "extend_till_ff", InspectSelection => "inspect_selection", InspectSelectionColor => "inspect_selection_color", @@ -400,9 +412,9 @@ impl TryFrom<&str> for BufferAction { "align_view_bottom" => Ok(AlignViewBottom), "align_view_top" => Ok(AlignViewTop), - "extend_to_mark" => Ok(ExtendToMark), - "extend_to_null" => Ok(ExtendToNull), - "extend_to_ff" => Ok(ExtendToFF), + "find_till_mark" => Ok(FindTillMark), + "find_till_null" => Ok(FindTillNull), + "find_till_ff" => Ok(FindTillFF), "inspect_selection" => Ok(InspectSelection), "inspect_selection_color" => Ok(InspectSelectionColor), diff --git a/src/buffer.rs b/src/buffer.rs index 29308fe..174fb7f 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -49,7 +49,7 @@ pub enum Mode { #[derive(Debug)] #[serde(rename_all = "snake_case")] pub enum PartialAction { - Goto, View, Replace, Space, Repeat, To + Goto, View, Replace, Space, Repeat, Till } #[derive(Clone, Copy, PartialEq, Eq)] @@ -69,7 +69,7 @@ impl TryFrom<&str> for PartialAction { "replace" => Ok(Replace), "space" => Ok(Space), "repeat" => Ok(Repeat), - "to" => Ok(To), + "to" => Ok(Till), _ => Err(()), } } diff --git a/src/buffer/actions.rs b/src/buffer/actions.rs index cba6404..0e71703 100644 --- a/src/buffer/actions.rs +++ b/src/buffer/actions.rs @@ -62,9 +62,13 @@ impl Buffer { BufferAction::AlignViewBottom => self.align_view_bottom(window_size), BufferAction::AlignViewTop => self.align_view_top(), - BufferAction::ExtendToMark => self.extend_to_mark(window_size), - BufferAction::ExtendToNull => self.extend_to_null(window_size), - BufferAction::ExtendToFF => self.extend_to_FF(window_size), + BufferAction::FindTillMark => self.till_mark(false, window_size), // extend: false + BufferAction::FindTillNull => self.till_null(false, window_size), // extend: false + BufferAction::FindTillFF => self.till_FF(false, window_size), // extend: false + + BufferAction::ExtendTillMark => self.till_mark(true, window_size), // extend: true + BufferAction::ExtendTillNull => self.till_null(true, window_size), // extend: true + BufferAction::ExtendTillFF => self.till_FF(true, window_size), // extend: true BufferAction::InspectSelection => self.inspect_selection(), BufferAction::InspectSelectionColor => self.inspect_selection_color(), @@ -102,7 +106,7 @@ impl Buffer { } const fn to(&mut self) { - self.partial_action = Some(PartialAction::To); + self.partial_action = Some(PartialAction::Till); } pub fn scroll_down(&mut self, window_size: WindowSize) { @@ -557,7 +561,7 @@ impl Buffer { .saturating_sub(BYTES_OF_PADDING); } - fn extend_to_mark(&mut self, window_size: WindowSize) { + fn till_mark(&mut self, extend: bool, window_size: WindowSize) { let mut sorted_marks: Vec<_> = self.marks.iter().copied().collect(); sorted_marks.sort_unstable(); @@ -569,7 +573,9 @@ impl Buffer { max_contents_index ); - self.primary_cursor.tail = self.primary_cursor.head; + if !extend { + self.primary_cursor.tail = self.primary_cursor.head; + } self.primary_cursor.head = mark_after_primary - 1; for cursor in &mut self.cursors { @@ -579,7 +585,9 @@ impl Buffer { max_contents_index ); - cursor.tail = cursor.head; + if !extend { + cursor.tail = cursor.head; + } cursor.head = mark_after_cursor - 1; } @@ -587,13 +595,15 @@ impl Buffer { self.clamp_screen_to_primary_cursor(window_size); } - fn extend_to_null(&mut self, window_size: WindowSize) { + fn till_null(&mut self, extend: bool, window_size: WindowSize) { if let Some(null_offset_after_primary) = self.contents[self.primary_cursor.head..] .iter() .skip(1) .position(|&byte| byte == 0) { - self.primary_cursor.tail = self.primary_cursor.head; + if !extend { + self.primary_cursor.tail = self.primary_cursor.head; + } self.primary_cursor.head += null_offset_after_primary; } @@ -603,7 +613,9 @@ impl Buffer { .skip(1) .position(|&byte| byte == 0) { - cursor.tail = cursor.head; + if !extend { + cursor.tail = cursor.head; + } cursor.head += null_offset_after_primary; } } @@ -613,13 +625,15 @@ impl Buffer { } #[allow(non_snake_case)] - fn extend_to_FF(&mut self, window_size: WindowSize) { + fn till_FF(&mut self, extend: bool, window_size: WindowSize) { if let Some(null_offset_after_primary) = self.contents[self.primary_cursor.head..] .iter() .skip(1) .position(|&byte| byte == 0xFF) { - self.primary_cursor.tail = self.primary_cursor.head; + if !extend { + self.primary_cursor.tail = self.primary_cursor.head; + } self.primary_cursor.head += null_offset_after_primary; } @@ -629,7 +643,9 @@ impl Buffer { .skip(1) .position(|&byte| byte == 0xFF) { - cursor.tail = cursor.head; + if !extend { + cursor.tail = cursor.head; + } cursor.head += null_offset_after_primary; } } diff --git a/src/buffer/widget/extra_statuses.rs b/src/buffer/widget/extra_statuses.rs index 1057953..23028aa 100644 --- a/src/buffer/widget/extra_statuses.rs +++ b/src/buffer/widget/extra_statuses.rs @@ -28,7 +28,7 @@ impl PartialAction { Replace => "r", Space => "␠", Repeat => "×", - To => "t", + Till => "t", } } } diff --git a/src/config/default.rs b/src/config/default.rs index 9db01d7..cbe13a3 100644 --- a/src/config/default.rs +++ b/src/config/default.rs @@ -138,10 +138,10 @@ impl Default for Config { (keypress("C"), CopySelectionOnNextLine.into()), ].into()), - (Some(PartialAction::To), [ - (keypress("m"), ExtendToMark.into()), - (keypress("0"), ExtendToNull.into()), - (keypress("f"), ExtendToFF.into()), + (Some(PartialAction::Till), [ + (keypress("m"), FindTillMark.into()), + (keypress("0"), FindTillNull.into()), + (keypress("f"), FindTillFF.into()), ].into()), ].into()), (Mode::Select, [ @@ -259,10 +259,10 @@ impl Default for Config { (keypress("C"), CopySelectionOnNextLine.into()), ].into()), - (Some(PartialAction::To), [ - (keypress("m"), ExtendToMark.into()), - (keypress("0"), ExtendToNull.into()), - (keypress("f"), ExtendToFF.into()), + (Some(PartialAction::Till), [ + (keypress("m"), ExtendTillMark.into()), + (keypress("0"), ExtendTillNull.into()), + (keypress("f"), ExtendTillFF.into()), ].into()), ].into()) ].into() diff --git a/src/main.rs b/src/main.rs index 379e699..7d3f820 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,6 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE; // - update showcase // - fix scroll clamping // - inspector translations for varint -// - t in select mode doesnt work right // - repeat in select mode doesnt work right // - gg/G in select mode // - gl/gj in select mode