This commit is contained in:
sxyazi 2025-03-27 23:56:43 +08:00
parent 2ee3be203d
commit 698520ab05
No known key found for this signature in database
6 changed files with 33 additions and 21 deletions

View file

@ -1,30 +1,31 @@
use yazi_fs::Step;
use yazi_macro::render;
use yazi_shared::event::{CmdCow, Data};
use yazi_shared::event::CmdCow;
use crate::help::Help;
struct Opt {
step: isize,
step: Step,
}
impl From<CmdCow> for Opt {
fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } }
fn from(c: CmdCow) -> Self {
Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() }
}
}
impl From<isize> for Opt {
fn from(step: isize) -> Self { Self { step } }
fn from(n: isize) -> Self { Self { step: n.into() } }
}
impl Help {
#[yazi_codegen::command]
pub fn arrow(&mut self, opt: Opt) {
let max = self.bindings.len().saturating_sub(1);
self.offset = self.offset.min(max);
self.cursor = self.cursor.min(max);
if opt.step > 0 {
self.next(opt.step as usize);
let new = opt.step.add(self.cursor, self.bindings.len(), Self::limit());
if new > self.cursor {
self.next(new);
} else {
self.prev(opt.step.unsigned_abs());
self.prev(new);
}
}

View file

@ -1,15 +1,18 @@
use yazi_fs::Step;
use yazi_macro::render;
use yazi_proxy::MgrProxy;
use yazi_shared::event::{CmdCow, Data};
use yazi_shared::event::CmdCow;
use crate::spot::Spot;
struct Opt {
step: isize,
step: Step,
}
impl From<CmdCow> for Opt {
fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } }
fn from(c: CmdCow) -> Self {
Self { step: c.first().and_then(|d| d.try_into().ok()).unwrap_or_default() }
}
}
impl Spot {
@ -17,12 +20,12 @@ impl Spot {
pub fn arrow(&mut self, opt: Opt) {
let Some(lock) = &mut self.lock else { return };
let new = opt.step.add(self.skip, lock.len().unwrap_or(u16::MAX as _), 0);
let Some(old) = lock.selected() else {
let new = self.skip.saturating_add_signed(opt.step);
return MgrProxy::spot(Some(new));
};
lock.select(Some(old.saturating_add_signed(opt.step)));
lock.select(Some(new));
let new = lock.selected().unwrap();
self.skip = new;

View file

@ -1,14 +1,16 @@
use std::borrow::Cow;
use yazi_proxy::{MgrProxy, TabProxy};
use yazi_shared::event::{CmdCow, Data};
use yazi_shared::event::CmdCow;
use crate::spot::Spot;
struct Opt {
step: isize,
step: Cow<'static, str>,
}
impl From<CmdCow> for Opt {
fn from(c: CmdCow) -> Self { Self { step: c.first().and_then(Data::as_isize).unwrap_or(0) } }
fn from(mut c: CmdCow) -> Self { Self { step: c.take_first_str().unwrap_or_default() } }
}
impl Spot {

View file

@ -82,6 +82,9 @@ impl Table {
table.render(self.area.transform(trans), buf, &mut self.state);
}
#[inline]
pub(crate) fn len(&self) -> usize { self.rows.len() }
pub(crate) fn select(&mut self, idx: Option<usize>) {
self
.state

View file

@ -32,6 +32,9 @@ impl TryFrom<Table> for SpotLock {
}
impl SpotLock {
#[inline]
pub fn len(&self) -> Option<usize> { Some(self.table()?.len()) }
pub fn select(&mut self, idx: Option<usize>) {
if let Some(t) = self.table_mut() {
t.select(idx);

View file

@ -17,8 +17,8 @@ impl TabProxy {
}
#[inline]
pub fn arrow(step: isize) {
emit!(Call(Cmd::args("mgr:arrow", &[step])));
pub fn arrow(step: impl AsRef<str>) {
emit!(Call(Cmd::args("mgr:arrow", &[step.as_ref()])));
}
#[inline]