From c014c95e1b2973457c2af8cbfacbfd63e30f8e11 Mon Sep 17 00:00:00 2001 From: SharzyL Date: Sun, 11 Jan 2026 11:13:38 +0100 Subject: [PATCH] word_motion: deduplicate type Co-authored-by: Johannes Altmanninger --- src/reader/reader.rs | 7 +------ src/reader/word_motion.rs | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 828631159..7e44c5243 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -121,6 +121,7 @@ have_proc_stat, hup_jobs, is_interactive_session, job_reap, jobs_requiring_warning_on_exit, print_exit_warning_for_jobs, proc_update_jiffies, }; +use crate::reader::word_motion::MoveWordDir; use crate::screen::is_dumb; use crate::screen::{CharOffset, Screen, screen_force_clear_to_end}; use crate::should_flog; @@ -2172,12 +2173,6 @@ fn delete_char(&mut self, backward: bool /* = true */) { } } -#[derive(Eq, PartialEq)] -enum MoveWordDir { - Left, - Right, -} - impl ReaderData { /// Move buffer position one word or erase one word. This function updates both the internal buffer /// and the screen. It is used by M-left, M-right and ^W to do block movement or block erase. diff --git a/src/reader/word_motion.rs b/src/reader/word_motion.rs index 866bb8e7f..58a1a3471 100644 --- a/src/reader/word_motion.rs +++ b/src/reader/word_motion.rs @@ -3,6 +3,12 @@ use crate::prelude::*; use crate::reader::is_backslashed; +#[derive(Eq, PartialEq)] +pub enum MoveWordDir { + Left, + Right, +} + pub enum MoveWordStyle { /// stop at punctuation Punctuation, @@ -225,20 +231,14 @@ fn is_path_component_character(c: char) -> bool { mod tests { use std::collections::HashSet; - use super::{MoveWordStateMachine, MoveWordStyle}; + use super::{MoveWordDir, MoveWordStateMachine, MoveWordStyle}; use crate::prelude::*; /// Test word motion (forward-word, etc.). Carets represent cursor stops. #[test] fn test_word_motion() { - #[derive(Eq, PartialEq)] - pub enum Direction { - Left, - Right, - } - fn validate_visitor( - direction: Direction, + direction: MoveWordDir, style: MoveWordStyle, line: &str, on_failure: fn(&str), @@ -255,7 +255,7 @@ fn validate_visitor( } } - let (mut idx, end) = if direction == Direction::Left { + let (mut idx, end) = if direction == MoveWordDir::Left { (*stops.iter().max().unwrap(), 0) } else { (*stops.iter().min().unwrap(), command.len()) @@ -264,7 +264,7 @@ fn validate_visitor( let mut sm = MoveWordStateMachine::new(style); while idx != end { - let char_idx = if direction == Direction::Left { + let char_idx = if direction == MoveWordDir::Left { idx - 1 } else { idx @@ -280,7 +280,7 @@ fn validate_visitor( if expected_stop { stops.remove(&idx); sm.reset(); - } else if direction == Direction::Left { + } else if direction == MoveWordDir::Left { idx -= 1; } else { idx += 1; @@ -294,7 +294,7 @@ macro_rules! validate { }; } - use Direction::*; + use MoveWordDir::*; use MoveWordStyle::*; // PathComponents tests