fix till in select mode

This commit is contained in:
alice pellerin
2026-04-25 18:08:46 -05:00
parent cd3ea4d1a6
commit cc0ae065c6
6 changed files with 64 additions and 37 deletions
+24 -12
View File
@@ -180,9 +180,13 @@ pub enum BufferAction {
AlignViewBottom, AlignViewBottom,
AlignViewTop, AlignViewTop,
ExtendToMark, FindTillMark,
ExtendToNull, FindTillNull,
ExtendToFF, FindTillFF,
ExtendTillMark,
ExtendTillNull,
ExtendTillFF,
InspectSelection, InspectSelection,
InspectSelectionColor, InspectSelectionColor,
@@ -250,9 +254,13 @@ impl BufferAction {
AlignViewBottom => false, AlignViewBottom => false,
AlignViewTop => false, AlignViewTop => false,
ExtendToMark => true, FindTillMark => true,
ExtendToNull => true, FindTillNull => true,
ExtendToFF => true, FindTillFF => true,
ExtendTillMark => true,
ExtendTillNull => true,
ExtendTillFF => true,
InspectSelection => true, InspectSelection => true,
InspectSelectionColor => true, InspectSelectionColor => true,
@@ -321,9 +329,13 @@ impl From<BufferAction> for &str {
AlignViewBottom => "align_view_bottom", AlignViewBottom => "align_view_bottom",
AlignViewTop => "align_view_top", AlignViewTop => "align_view_top",
ExtendToMark => "extend_to_mark", FindTillMark => "find_till_mark",
ExtendToNull => "extend_to_null", FindTillNull => "find_till_null",
ExtendToFF => "extend_to_ff", FindTillFF => "find_till_ff",
ExtendTillMark => "extend_till_mark",
ExtendTillNull => "extend_till_null",
ExtendTillFF => "extend_till_ff",
InspectSelection => "inspect_selection", InspectSelection => "inspect_selection",
InspectSelectionColor => "inspect_selection_color", InspectSelectionColor => "inspect_selection_color",
@@ -400,9 +412,9 @@ impl TryFrom<&str> for BufferAction {
"align_view_bottom" => Ok(AlignViewBottom), "align_view_bottom" => Ok(AlignViewBottom),
"align_view_top" => Ok(AlignViewTop), "align_view_top" => Ok(AlignViewTop),
"extend_to_mark" => Ok(ExtendToMark), "find_till_mark" => Ok(FindTillMark),
"extend_to_null" => Ok(ExtendToNull), "find_till_null" => Ok(FindTillNull),
"extend_to_ff" => Ok(ExtendToFF), "find_till_ff" => Ok(FindTillFF),
"inspect_selection" => Ok(InspectSelection), "inspect_selection" => Ok(InspectSelection),
"inspect_selection_color" => Ok(InspectSelectionColor), "inspect_selection_color" => Ok(InspectSelectionColor),
+2 -2
View File
@@ -49,7 +49,7 @@ pub enum Mode {
#[derive(Debug)] #[derive(Debug)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum PartialAction { pub enum PartialAction {
Goto, View, Replace, Space, Repeat, To Goto, View, Replace, Space, Repeat, Till
} }
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
@@ -69,7 +69,7 @@ impl TryFrom<&str> for PartialAction {
"replace" => Ok(Replace), "replace" => Ok(Replace),
"space" => Ok(Space), "space" => Ok(Space),
"repeat" => Ok(Repeat), "repeat" => Ok(Repeat),
"to" => Ok(To), "to" => Ok(Till),
_ => Err(()), _ => Err(()),
} }
} }
+29 -13
View File
@@ -62,9 +62,13 @@ impl Buffer {
BufferAction::AlignViewBottom => self.align_view_bottom(window_size), BufferAction::AlignViewBottom => self.align_view_bottom(window_size),
BufferAction::AlignViewTop => self.align_view_top(), BufferAction::AlignViewTop => self.align_view_top(),
BufferAction::ExtendToMark => self.extend_to_mark(window_size), BufferAction::FindTillMark => self.till_mark(false, window_size), // extend: false
BufferAction::ExtendToNull => self.extend_to_null(window_size), BufferAction::FindTillNull => self.till_null(false, window_size), // extend: false
BufferAction::ExtendToFF => self.extend_to_FF(window_size), 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::InspectSelection => self.inspect_selection(),
BufferAction::InspectSelectionColor => self.inspect_selection_color(), BufferAction::InspectSelectionColor => self.inspect_selection_color(),
@@ -102,7 +106,7 @@ impl Buffer {
} }
const fn to(&mut self) { 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) { pub fn scroll_down(&mut self, window_size: WindowSize) {
@@ -557,7 +561,7 @@ impl Buffer {
.saturating_sub(BYTES_OF_PADDING); .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(); let mut sorted_marks: Vec<_> = self.marks.iter().copied().collect();
sorted_marks.sort_unstable(); sorted_marks.sort_unstable();
@@ -569,7 +573,9 @@ impl Buffer {
max_contents_index 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; self.primary_cursor.head = mark_after_primary - 1;
for cursor in &mut self.cursors { for cursor in &mut self.cursors {
@@ -579,7 +585,9 @@ impl Buffer {
max_contents_index max_contents_index
); );
cursor.tail = cursor.head; if !extend {
cursor.tail = cursor.head;
}
cursor.head = mark_after_cursor - 1; cursor.head = mark_after_cursor - 1;
} }
@@ -587,13 +595,15 @@ impl Buffer {
self.clamp_screen_to_primary_cursor(window_size); 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..] if let Some(null_offset_after_primary) = self.contents[self.primary_cursor.head..]
.iter() .iter()
.skip(1) .skip(1)
.position(|&byte| byte == 0) .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; self.primary_cursor.head += null_offset_after_primary;
} }
@@ -603,7 +613,9 @@ impl Buffer {
.skip(1) .skip(1)
.position(|&byte| byte == 0) .position(|&byte| byte == 0)
{ {
cursor.tail = cursor.head; if !extend {
cursor.tail = cursor.head;
}
cursor.head += null_offset_after_primary; cursor.head += null_offset_after_primary;
} }
} }
@@ -613,13 +625,15 @@ impl Buffer {
} }
#[allow(non_snake_case)] #[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..] if let Some(null_offset_after_primary) = self.contents[self.primary_cursor.head..]
.iter() .iter()
.skip(1) .skip(1)
.position(|&byte| byte == 0xFF) .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; self.primary_cursor.head += null_offset_after_primary;
} }
@@ -629,7 +643,9 @@ impl Buffer {
.skip(1) .skip(1)
.position(|&byte| byte == 0xFF) .position(|&byte| byte == 0xFF)
{ {
cursor.tail = cursor.head; if !extend {
cursor.tail = cursor.head;
}
cursor.head += null_offset_after_primary; cursor.head += null_offset_after_primary;
} }
} }
+1 -1
View File
@@ -28,7 +28,7 @@ impl PartialAction {
Replace => "r", Replace => "r",
Space => "", Space => "",
Repeat => "×", Repeat => "×",
To => "t", Till => "t",
} }
} }
} }
+8 -8
View File
@@ -138,10 +138,10 @@ impl Default for Config {
(keypress("C"), CopySelectionOnNextLine.into()), (keypress("C"), CopySelectionOnNextLine.into()),
].into()), ].into()),
(Some(PartialAction::To), [ (Some(PartialAction::Till), [
(keypress("m"), ExtendToMark.into()), (keypress("m"), FindTillMark.into()),
(keypress("0"), ExtendToNull.into()), (keypress("0"), FindTillNull.into()),
(keypress("f"), ExtendToFF.into()), (keypress("f"), FindTillFF.into()),
].into()), ].into()),
].into()), ].into()),
(Mode::Select, [ (Mode::Select, [
@@ -259,10 +259,10 @@ impl Default for Config {
(keypress("C"), CopySelectionOnNextLine.into()), (keypress("C"), CopySelectionOnNextLine.into()),
].into()), ].into()),
(Some(PartialAction::To), [ (Some(PartialAction::Till), [
(keypress("m"), ExtendToMark.into()), (keypress("m"), ExtendTillMark.into()),
(keypress("0"), ExtendToNull.into()), (keypress("0"), ExtendTillNull.into()),
(keypress("f"), ExtendToFF.into()), (keypress("f"), ExtendTillFF.into()),
].into()), ].into()),
].into()) ].into())
].into() ].into()
-1
View File
@@ -43,7 +43,6 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE;
// - update showcase // - update showcase
// - fix scroll clamping // - fix scroll clamping
// - inspector translations for varint // - inspector translations for varint
// - t in select mode doesnt work right
// - repeat in select mode doesnt work right // - repeat in select mode doesnt work right
// - gg/G in select mode // - gg/G in select mode
// - gl/gj in select mode // - gl/gj in select mode