word_motion: deduplicate type

Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
This commit is contained in:
SharzyL
2026-01-11 11:13:38 +01:00
committed by Johannes Altmanninger
parent bd86f53b9f
commit c014c95e1b
2 changed files with 13 additions and 18 deletions

View File

@@ -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.

View File

@@ -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