mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Extract the logic of comparing two CharKind instances into a method of CharKind
This commit is contained in:
parent
bcf528d99e
commit
a058226576
3 changed files with 11 additions and 11 deletions
|
|
@ -22,13 +22,11 @@ impl Input {
|
|||
let mut it = snap.value[..idx].chars().rev().enumerate();
|
||||
let mut prev = CharKind::new(it.next().unwrap().1);
|
||||
for (i, c) in it {
|
||||
let c = CharKind::new(c);
|
||||
let new_char_kind =
|
||||
if opt.far { (c == CharKind::Space) != (prev == CharKind::Space) } else { c != prev };
|
||||
if prev != CharKind::Space && new_char_kind {
|
||||
let k = CharKind::new(c);
|
||||
if prev != CharKind::Space && prev.vary(k, opt.far) {
|
||||
return self.move_(-(i as isize));
|
||||
}
|
||||
prev = c;
|
||||
prev = k;
|
||||
}
|
||||
|
||||
if prev != CharKind::Space {
|
||||
|
|
|
|||
|
|
@ -22,20 +22,18 @@ impl Input {
|
|||
};
|
||||
|
||||
for (i, c) in it {
|
||||
let c = CharKind::new(c);
|
||||
let new_char_kind =
|
||||
if opt.far { (c == CharKind::Space) != (prev == CharKind::Space) } else { c != prev };
|
||||
let k = CharKind::new(c);
|
||||
let b = if opt.end_of_word {
|
||||
prev != CharKind::Space && new_char_kind && i != 1
|
||||
prev != CharKind::Space && prev.vary(k, opt.far) && i != 1
|
||||
} else {
|
||||
c != CharKind::Space && new_char_kind
|
||||
k != CharKind::Space && k.vary(prev, opt.far)
|
||||
};
|
||||
if b && !matches!(snap.op, InputOp::None | InputOp::Select(_)) {
|
||||
return self.move_(i as isize);
|
||||
} else if b {
|
||||
return self.move_(if opt.end_of_word { i - 1 } else { i } as isize);
|
||||
}
|
||||
prev = c;
|
||||
prev = k;
|
||||
}
|
||||
|
||||
self.move_(snap.len() as isize)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,10 @@ impl CharKind {
|
|||
Self::Other
|
||||
}
|
||||
}
|
||||
|
||||
pub fn vary(self, other: Self, far: bool) -> bool {
|
||||
if far { (self == Self::Space) != (other == Self::Space) } else { self != other }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn strip_trailing_newline(mut s: String) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue