refactor: rename move_::Step to move_::OptStep

This commit is contained in:
darcy 2025-01-03 11:33:14 +11:00 committed by sxyazi
parent a53f896763
commit ab268a85df
No known key found for this signature in database

View file

@ -5,11 +5,11 @@ use yazi_shared::event::{CmdCow, Data};
use crate::input::{Input, op::InputOp, snap::InputSnap}; use crate::input::{Input, op::InputOp, snap::InputSnap};
struct Opt { struct Opt {
step: Step, step: OptStep,
in_operating: bool, in_operating: bool,
} }
enum Step { enum OptStep {
Offset(isize), Offset(isize),
Bol, Bol,
Eol, Eol,
@ -17,22 +17,22 @@ enum Step {
LastChar, LastChar,
} }
impl TryFrom<&Data> for Step { impl TryFrom<&Data> for OptStep {
type Error = (); type Error = ();
fn try_from(d: &Data) -> Result<Self, Self::Error> { fn try_from(d: &Data) -> Result<Self, Self::Error> {
if let Some(offset) = d.as_isize() { if let Some(offset) = d.as_isize() {
return Ok(Step::Offset(offset)); return Ok(OptStep::Offset(offset));
}; };
if let Some(s) = d.as_str() { if let Some(s) = d.as_str() {
if let Ok(offset) = s.parse() { if let Ok(offset) = s.parse() {
return Ok(Step::Offset(offset)); return Ok(OptStep::Offset(offset));
}; };
match s.as_ref() { match s.as_ref() {
"bol" => return Ok(Step::Bol), "bol" => return Ok(OptStep::Bol),
"eol" => return Ok(Step::Eol), "eol" => return Ok(OptStep::Eol),
"first-char" => return Ok(Step::FirstChar), "first-char" => return Ok(OptStep::FirstChar),
"last-char" => return Ok(Step::LastChar), "last-char" => return Ok(OptStep::LastChar),
_ => (), _ => (),
} }
} }
@ -51,7 +51,7 @@ impl From<CmdCow> for Opt {
impl From<isize> for Opt { impl From<isize> for Opt {
fn from(step: isize) -> Self { fn from(step: isize) -> Self {
Self { Self {
step: Step::Offset(step), step: OptStep::Offset(step),
in_operating: false, in_operating: false,
} }
} }
@ -66,15 +66,15 @@ impl Input {
} }
let position = match opt.step { let position = match opt.step {
Step::Offset(offset) => OptStep::Offset(offset) =>
if offset <= 0 { if offset <= 0 {
snap.cursor.saturating_sub(offset.unsigned_abs()) snap.cursor.saturating_sub(offset.unsigned_abs())
} else { } else {
snap.count().min(snap.cursor + offset as usize) snap.count().min(snap.cursor + offset as usize)
}, },
Step::Bol => 0, OptStep::Bol => 0,
Step::Eol => snap.count(), OptStep::Eol => snap.count(),
Step::FirstChar => snap OptStep::FirstChar => snap
.value .value
.chars() .chars()
.enumerate() .enumerate()
@ -82,7 +82,7 @@ impl Input {
.map(|(i, _)| i) .map(|(i, _)| i)
.next() .next()
.unwrap_or(0), .unwrap_or(0),
Step::LastChar => snap OptStep::LastChar => snap
.value .value
.chars() .chars()
.rev() .rev()