mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: add --big parameter to forward and backward commands
This commit is contained in:
parent
e0cbe78377
commit
90ccc63244
3 changed files with 40 additions and 11 deletions
|
|
@ -249,11 +249,14 @@ keymap = [
|
||||||
{ on = "<C-f>", run = "move 1", desc = "Move forward a character" },
|
{ on = "<C-f>", run = "move 1", desc = "Move forward a character" },
|
||||||
|
|
||||||
# Word-wise movement
|
# Word-wise movement
|
||||||
{ on = "b", run = "backward", desc = "Move back to the start of the current or previous word" },
|
{ on = "b", run = "backward", desc = "Move back to the start of the current or previous word" },
|
||||||
{ on = "w", run = "forward", desc = "Move forward to the start of the next word" },
|
{ on = "w", run = "forward", desc = "Move forward to the start of the next word" },
|
||||||
{ on = "e", run = "forward --end-of-word", desc = "Move forward to the end of the current or next word" },
|
{ on = "e", run = "forward --end-of-word", desc = "Move forward to the end of the current or next word" },
|
||||||
{ on = "<A-b>", run = "backward", desc = "Move back to the start of the current or previous word" },
|
{ on = "B", run = "backward --big", desc = "Move back to the start of the current or previous WORD" },
|
||||||
{ on = "<A-f>", run = "forward --end-of-word", desc = "Move forward to the end of the current or next word" },
|
{ on = "W", run = "forward --big", desc = "Move forward to the start of the next WORD" },
|
||||||
|
{ on = "E", run = "forward --big --end-of-word", desc = "Move forward to the end of the current or next WORD" },
|
||||||
|
{ on = "<A-b>", run = "backward", desc = "Move back to the start of the current or previous word" },
|
||||||
|
{ on = "<A-f>", run = "forward --end-of-word", desc = "Move forward to the end of the current or next word" },
|
||||||
|
|
||||||
# Line-wise movement
|
# Line-wise movement
|
||||||
{ on = "0", run = "move bol", desc = "Move to the BOL" },
|
{ on = "0", run = "move bol", desc = "Move to the BOL" },
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,18 @@ use yazi_shared::{CharKind, event::CmdCow};
|
||||||
|
|
||||||
use crate::input::Input;
|
use crate::input::Input;
|
||||||
|
|
||||||
|
struct Opt {
|
||||||
|
big: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<CmdCow> for Opt {
|
||||||
|
fn from(c: CmdCow) -> Self { Self { big: c.bool("big") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Input {
|
impl Input {
|
||||||
pub fn backward(&mut self, _: CmdCow) {
|
#[yazi_codegen::command]
|
||||||
|
pub fn backward(&mut self, opt: Opt) {
|
||||||
let snap = self.snap();
|
let snap = self.snap();
|
||||||
if snap.cursor == 0 {
|
if snap.cursor == 0 {
|
||||||
return self.move_(0);
|
return self.move_(0);
|
||||||
|
|
@ -14,7 +24,12 @@ impl Input {
|
||||||
let mut prev = CharKind::new(it.next().unwrap().1);
|
let mut prev = CharKind::new(it.next().unwrap().1);
|
||||||
for (i, c) in it {
|
for (i, c) in it {
|
||||||
let c = CharKind::new(c);
|
let c = CharKind::new(c);
|
||||||
if prev != CharKind::Space && prev != c {
|
let new_char_kind = if opt.big {
|
||||||
|
(c == CharKind::Space) != (prev == CharKind::Space)
|
||||||
|
} else {
|
||||||
|
c != prev
|
||||||
|
};
|
||||||
|
if prev != CharKind::Space && new_char_kind {
|
||||||
return self.move_(-(i as isize));
|
return self.move_(-(i as isize));
|
||||||
}
|
}
|
||||||
prev = c;
|
prev = c;
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,16 @@ use crate::input::{Input, op::InputOp};
|
||||||
|
|
||||||
struct Opt {
|
struct Opt {
|
||||||
end_of_word: bool,
|
end_of_word: bool,
|
||||||
|
big: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<CmdCow> for Opt {
|
impl From<CmdCow> for Opt {
|
||||||
fn from(c: CmdCow) -> Self { Self { end_of_word: c.bool("end-of-word") } }
|
fn from(c: CmdCow) -> Self {
|
||||||
|
Self {
|
||||||
|
end_of_word: c.bool("end-of-word"),
|
||||||
|
big: c.bool("big"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Input {
|
impl Input {
|
||||||
|
|
@ -22,10 +28,15 @@ impl Input {
|
||||||
|
|
||||||
for (i, c) in it {
|
for (i, c) in it {
|
||||||
let c = CharKind::new(c);
|
let c = CharKind::new(c);
|
||||||
let b = if opt.end_of_word {
|
let new_char_kind = if opt.big {
|
||||||
prev != CharKind::Space && prev != c && i != 1
|
(c == CharKind::Space) != (prev == CharKind::Space)
|
||||||
} else {
|
} else {
|
||||||
c != CharKind::Space && c != prev
|
c != prev
|
||||||
|
};
|
||||||
|
let b = if opt.end_of_word {
|
||||||
|
prev != CharKind::Space && new_char_kind && i != 1
|
||||||
|
} else {
|
||||||
|
c != CharKind::Space && new_char_kind
|
||||||
};
|
};
|
||||||
if b && !matches!(snap.op, InputOp::None | InputOp::Select(_)) {
|
if b && !matches!(snap.op, InputOp::None | InputOp::Select(_)) {
|
||||||
return self.move_(i as isize);
|
return self.move_(i as isize);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue