This commit is contained in:
sxyazi 2024-01-02 01:21:32 +08:00
parent 159d59a0ea
commit a54af2e66f
No known key found for this signature in database
43 changed files with 199 additions and 201 deletions

View file

@ -1,6 +1,6 @@
use std::{mem, ops::ControlFlow};
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::completion::Completion;
@ -54,28 +54,28 @@ impl Completion {
prefixed.into_iter().map(ToOwned::to_owned).collect()
}
pub fn show<'a>(&mut self, opt: impl Into<Opt<'a>>) -> bool {
pub fn show<'a>(&mut self, opt: impl Into<Opt<'a>>) {
let opt = opt.into() as Opt;
if self.ticket != opt.ticket {
return false;
return;
}
if !opt.cache.is_empty() {
self.caches.insert(opt.cache_name.to_owned(), opt.cache.clone());
}
let Some(cache) = self.caches.get(opt.cache_name) else {
return false;
return;
};
self.ticket = opt.ticket;
self.cands = Self::match_candidates(opt.word, cache);
if self.cands.is_empty() {
return mem::replace(&mut self.visible, false);
return render!(mem::replace(&mut self.visible, false));
}
self.offset = 0;
self.cursor = 0;
self.visible = true;
true
render!();
}
}

View file

@ -1,7 +1,7 @@
use std::{mem, path::{MAIN_SEPARATOR, MAIN_SEPARATOR_STR}};
use tokio::fs;
use yazi_shared::{emit, event::Exec, Layer};
use yazi_shared::{emit, event::Exec, render, Layer};
use crate::completion::Completion;
@ -28,10 +28,10 @@ impl Completion {
));
}
pub fn trigger<'a>(&mut self, opt: impl Into<Opt<'a>>) -> bool {
pub fn trigger<'a>(&mut self, opt: impl Into<Opt<'a>>) {
let opt = opt.into() as Opt;
if opt.ticket < self.ticket {
return false;
return;
}
self.ticket = opt.ticket;
@ -76,7 +76,7 @@ impl Completion {
Ok::<(), anyhow::Error>(())
});
mem::replace(&mut self.visible, false)
render!(mem::replace(&mut self.visible, false));
}
#[inline]

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::help::Help;
@ -17,19 +17,23 @@ impl From<isize> for Opt {
impl Help {
#[inline]
pub fn arrow(&mut self, opt: impl Into<Opt>) -> bool {
pub fn arrow(&mut self, opt: impl Into<Opt>) {
let max = self.bindings.len().saturating_sub(1);
self.offset = self.offset.min(max);
self.cursor = self.cursor.min(max);
let opt = opt.into() as Opt;
if opt.step > 0 { self.next(opt.step as usize) } else { self.prev(opt.step.unsigned_abs()) }
if opt.step > 0 {
self.next(opt.step as usize);
} else {
self.prev(opt.step.unsigned_abs());
}
}
fn next(&mut self, step: usize) -> bool {
fn next(&mut self, step: usize) {
let len = self.bindings.len();
if len == 0 {
return false;
return;
}
let old = self.cursor;
@ -40,10 +44,10 @@ impl Help {
self.offset = len.saturating_sub(limit).min(self.offset + self.cursor - old);
}
old != self.cursor
render!(old != self.cursor);
}
fn prev(&mut self, step: usize) -> bool {
fn prev(&mut self, step: usize) {
let old = self.cursor;
self.cursor = self.cursor.saturating_sub(step);
@ -51,6 +55,6 @@ impl Help {
self.offset = self.offset.saturating_sub(old - self.cursor);
}
old != self.cursor
render!(old != self.cursor);
}
}

View file

@ -1,15 +1,15 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::help::Help;
impl Help {
pub fn escape(&mut self, _: &Exec) -> bool {
if self.in_filter.is_some() {
self.in_filter = None;
self.filter_apply();
true
} else {
self.toggle(self.layer)
pub fn escape(&mut self, _: &Exec) {
if self.in_filter.is_none() {
return self.toggle(self.layer);
}
self.in_filter = None;
self.filter_apply();
render!();
}
}

View file

@ -1,7 +1,7 @@
use crossterm::event::KeyCode;
use unicode_width::UnicodeWidthStr;
use yazi_config::{keymap::{Control, Key}, KEYMAP};
use yazi_shared::{term::Term, Layer};
use yazi_shared::{render, term::Term, Layer};
use super::HELP_MARGIN;
use crate::input::Input;
@ -24,7 +24,7 @@ impl Help {
#[inline]
pub fn limit() -> usize { Term::size().rows.saturating_sub(HELP_MARGIN) as usize }
pub fn toggle(&mut self, layer: Layer) -> bool {
pub fn toggle(&mut self, layer: Layer) {
self.visible = !self.visible;
self.layer = layer;
@ -34,7 +34,7 @@ impl Help {
self.offset = 0;
self.cursor = 0;
true
render!();
}
pub(super) fn filter_apply(&mut self) -> bool {
@ -54,24 +54,23 @@ impl Help {
true
}
pub fn type_(&mut self, key: &Key) -> bool {
pub fn type_(&mut self, key: &Key) {
let Some(input) = &mut self.in_filter else {
return false;
return;
};
if key.is_enter() {
self.in_filter = None;
return true;
return render!();
}
let b = match &key {
match &key {
Key { code: KeyCode::Backspace, shift: false, ctrl: false, alt: false } => {
input.backspace(false)
}
_ => input.type_(key),
};
if b { self.filter_apply() } else { false }
}
self.filter_apply();
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::input::Input;
@ -14,14 +14,14 @@ impl From<bool> for Opt {
}
impl Input {
pub fn backspace(&mut self, opt: impl Into<Opt>) -> bool {
pub fn backspace(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
let snap = self.snaps.current_mut();
if !opt.under && snap.cursor < 1 {
return false;
return;
} else if opt.under && snap.cursor >= snap.value.len() {
return false;
return;
}
if opt.under {
@ -33,6 +33,6 @@ impl Input {
}
self.flush_value();
true
render!();
}
}

View file

@ -3,7 +3,7 @@ use yazi_shared::{event::Exec, CharKind};
use crate::input::Input;
impl Input {
pub fn backward(&mut self, _: &Exec) -> bool {
pub fn backward(&mut self, _: &Exec) {
let snap = self.snap();
if snap.cursor == 0 {
return self.move_(0);
@ -23,6 +23,5 @@ impl Input {
if prev != CharKind::Space {
return self.move_(-(snap.len() as isize));
}
false
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::{event::Exec, InputError};
use yazi_shared::{event::Exec, render, InputError};
use crate::{completion::Completion, input::Input};
@ -14,7 +14,7 @@ impl From<bool> for Opt {
}
impl Input {
pub fn close(&mut self, opt: impl Into<Opt>) -> bool {
pub fn close(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
if self.completion {
@ -28,6 +28,6 @@ impl Input {
self.ticket = self.ticket.wrapping_add(1);
self.visible = false;
true
render!();
}
}

View file

@ -1,6 +1,6 @@
use std::path::MAIN_SEPARATOR;
use yazi_shared::{emit, event::Exec, Layer};
use yazi_shared::{emit, event::Exec, render, Layer};
use crate::input::Input;
@ -27,10 +27,10 @@ impl Input {
));
}
pub fn complete<'a>(&mut self, opt: impl Into<Opt<'a>>) -> bool {
pub fn complete<'a>(&mut self, opt: impl Into<Opt<'a>>) {
let opt = opt.into() as Opt;
if self.ticket != opt.ticket {
return false;
return;
}
let [before, after] = self.partition();
@ -42,7 +42,7 @@ impl Input {
let snap = self.snaps.current_mut();
if new == snap.value {
return false;
return;
}
let delta = new.chars().count() as isize - snap.value.chars().count() as isize;
@ -50,6 +50,6 @@ impl Input {
self.move_(delta);
self.flush_value();
true
render!();
}
}

View file

@ -14,22 +14,24 @@ impl From<&Exec> for Opt {
}
impl Input {
pub fn delete(&mut self, opt: impl Into<Opt>) -> bool {
pub fn delete(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
match self.snap().op {
InputOp::None => {
self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, self.snap().cursor);
false
}
InputOp::Select(start) => {
self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, start);
return self.handle_op(self.snap().cursor, true).then(|| self.move_(0)).is_some();
// TODO: render
todo!();
// return self.handle_op(self.snap().cursor, true).then(||
// self.move_(0)).is_some();
}
InputOp::Delete(..) => {
self.snap_mut().op = InputOp::Delete(opt.cut, opt.insert, 0);
return self.move_(self.snap().len() as isize);
self.move_(self.snap().len() as isize);
}
_ => false,
_ => {}
}
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::{completion::Completion, input::{op::InputOp, Input, InputMode}};
@ -12,7 +12,7 @@ impl From<()> for Opt {
}
impl Input {
pub fn escape(&mut self, _: impl Into<Opt>) -> bool {
pub fn escape(&mut self, _: impl Into<Opt>) {
let snap = self.snap_mut();
match snap.mode {
InputMode::Normal if snap.op == InputOp::None => {
@ -31,6 +31,6 @@ impl Input {
}
}
self.snaps.tag(self.limit());
true
render!();
}
}

View file

@ -11,7 +11,7 @@ impl From<&Exec> for Opt {
}
impl Input {
pub fn forward(&mut self, opt: impl Into<Opt>) -> bool {
pub fn forward(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
let snap = self.snap();

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::input::{op::InputOp, Input, InputMode};
@ -14,13 +14,13 @@ impl From<bool> for Opt {
}
impl Input {
pub fn insert(&mut self, opt: impl Into<Opt>) -> bool {
pub fn insert(&mut self, opt: impl Into<Opt>) {
let snap = self.snap_mut();
if snap.mode == InputMode::Normal {
snap.op = InputOp::None;
snap.mode = InputMode::Insert;
} else {
return false;
return;
}
let opt = opt.into() as Opt;
@ -28,6 +28,6 @@ impl Input {
self.move_(1);
}
true
render!();
}
}

View file

@ -1,6 +1,6 @@
use std::ops::RangeBounds;
use yazi_shared::{event::Exec, CharKind};
use yazi_shared::{event::Exec, render, CharKind};
use crate::input::Input;
@ -15,7 +15,7 @@ impl<'a> From<&'a Exec> for Opt<'a> {
}
impl Input {
fn kill_range(&mut self, range: impl RangeBounds<usize>) -> bool {
fn kill_range(&mut self, range: impl RangeBounds<usize>) {
let snap = self.snap_mut();
snap.cursor = match range.start_bound() {
std::ops::Bound::Included(i) => *i,
@ -23,12 +23,12 @@ impl Input {
std::ops::Bound::Unbounded => 0,
};
if snap.value.drain(range).next().is_none() {
return false;
return;
}
self.move_(0);
self.flush_value();
true
render!();
}
/// Searches for a word boundary and returns the movement in the cursor
@ -66,7 +66,7 @@ impl Input {
spaces + count_characters(input.skip(spaces))
}
pub fn kill<'a>(&mut self, opt: impl Into<Opt<'a>>) -> bool {
pub fn kill<'a>(&mut self, opt: impl Into<Opt<'a>>) {
let opt = opt.into() as Opt;
let snap = self.snap_mut();
@ -89,7 +89,7 @@ impl Input {
let end = start + Self::find_word_boundary(snap.value[start..].chars());
self.kill_range(start..end)
}
_ => false,
_ => {}
}
}
}

View file

@ -1,5 +1,5 @@
use unicode_width::UnicodeWidthStr;
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::input::{op::InputOp, snap::InputSnap, Input};
@ -21,22 +21,22 @@ impl From<isize> for Opt {
}
impl Input {
pub fn move_(&mut self, opt: impl Into<Opt>) -> bool {
pub fn move_(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
let snap = self.snap();
if opt.in_operating && snap.op == InputOp::None {
return false;
return;
}
let b = self.handle_op(
render!(self.handle_op(
if opt.step <= 0 {
snap.cursor.saturating_sub(opt.step.unsigned_abs())
} else {
snap.count().min(snap.cursor + opt.step as usize)
},
false,
);
));
let (limit, snap) = (self.limit(), self.snap_mut());
if snap.offset > snap.cursor {
@ -51,7 +51,5 @@ impl Input {
snap.offset = snap.cursor - InputSnap::find_window(&s, 0, limit).end.saturating_sub(delta);
}
}
b
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::{input::{op::InputOp, Input}, CLIPBOARD};
@ -11,7 +11,7 @@ impl From<&Exec> for Opt {
}
impl Input {
pub fn paste(&mut self, opt: impl Into<Opt>) -> bool {
pub fn paste(&mut self, opt: impl Into<Opt>) {
if let Some(start) = self.snap().op.start() {
self.snap_mut().op = InputOp::Delete(false, false, start);
self.handle_op(self.snap().cursor, true);
@ -19,13 +19,13 @@ impl Input {
let s = futures::executor::block_on(CLIPBOARD.get());
if s.is_empty() {
return false;
return;
}
let opt = opt.into() as Opt;
self.insert(!opt.before);
self.type_str(&s.to_string_lossy());
self.escape(());
true
render!();
}
}

View file

@ -1,7 +1,9 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::input::Input;
impl Input {
pub fn redo(&mut self, _: &Exec) -> bool { self.snaps.redo() }
pub fn redo(&mut self, _: &Exec) {
render!(self.snaps.redo());
}
}

View file

@ -1,7 +1,7 @@
use anyhow::anyhow;
use tokio::sync::mpsc;
use yazi_config::popup::InputCfg;
use yazi_shared::{emit, event::Exec, InputError, Layer};
use yazi_shared::{emit, event::Exec, render, InputError, Layer};
use crate::input::Input;
@ -25,9 +25,9 @@ impl Input {
rx
}
pub fn show(&mut self, opt: impl TryInto<Opt>) -> bool {
pub fn show(&mut self, opt: impl TryInto<Opt>) {
let Ok(opt) = opt.try_into() else {
return false;
return;
};
self.close(false);
@ -45,6 +45,6 @@ impl Input {
// Reset snaps
self.snaps.reset(opt.cfg.value, self.limit());
true
render!();
}
}

View file

@ -1,5 +1,5 @@
use yazi_config::keymap::Key;
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::input::{Input, InputMode};
@ -10,15 +10,14 @@ impl From<&Exec> for Opt {
}
impl Input {
pub fn type_(&mut self, key: &Key) -> bool {
pub fn type_(&mut self, key: &Key) {
if self.mode() != InputMode::Insert {
return false;
return;
}
if let Some(c) = key.plain() {
let mut bits = [0; 4];
return self.type_str(c.encode_utf8(&mut bits));
render!(self.type_str(c.encode_utf8(&mut bits)));
}
false
}
}

View file

@ -1,15 +1,15 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::input::{Input, InputMode};
impl Input {
pub fn undo(&mut self, _: &Exec) -> bool {
pub fn undo(&mut self, _: &Exec) {
if !self.snaps.undo() {
return false;
return;
}
if self.snap().mode == InputMode::Insert {
self.escape(());
}
true
render!();
}
}

View file

@ -1,18 +1,18 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::input::{op::InputOp, Input, InputMode};
impl Input {
#[inline]
pub fn visual(&mut self, _: &Exec) -> bool {
pub fn visual(&mut self, _: &Exec) {
let snap = self.snap_mut();
if snap.mode != InputMode::Normal {
return false;
return;
} else if snap.value.is_empty() {
return false;
return;
}
snap.op = InputOp::Select(snap.cursor);
true
render!();
}
}

View file

@ -3,22 +3,23 @@ use yazi_shared::event::Exec;
use crate::input::{op::InputOp, Input};
impl Input {
pub fn yank(&mut self, _: &Exec) -> bool {
pub fn yank(&mut self, _: &Exec) {
match self.snap().op {
InputOp::None => {
self.snap_mut().op = InputOp::Yank(self.snap().cursor);
false
}
InputOp::Select(start) => {
self.snap_mut().op = InputOp::Yank(start);
return self.handle_op(self.snap().cursor, true).then(|| self.move_(0)).is_some();
// TODO: render
todo!();
// return self.handle_op(self.snap().cursor, true).then(||
// self.move_(0)).is_some();
}
InputOp::Yank(_) => {
self.snap_mut().op = InputOp::Yank(0);
self.move_(self.snap().len() as isize);
false
}
_ => false,
_ => {}
}
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::select::Select;
@ -13,10 +13,10 @@ impl From<&Exec> for Opt {
}
impl Select {
fn next(&mut self, step: usize) -> bool {
fn next(&mut self, step: usize) {
let len = self.items.len();
if len == 0 {
return false;
return;
}
let old = self.cursor;
@ -27,10 +27,10 @@ impl Select {
self.offset = len.saturating_sub(limit).min(self.offset + self.cursor - old);
}
old != self.cursor
render!(old != self.cursor);
}
fn prev(&mut self, step: usize) -> bool {
fn prev(&mut self, step: usize) {
let old = self.cursor;
self.cursor = self.cursor.saturating_sub(step);
@ -38,10 +38,10 @@ impl Select {
self.offset = self.offset.saturating_sub(old - self.cursor);
}
old != self.cursor
render!(old != self.cursor);
}
pub fn arrow(&mut self, opt: impl Into<Opt>) -> bool {
pub fn arrow(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
if opt.step > 0 { self.next(opt.step as usize) } else { self.prev(opt.step.unsigned_abs()) }
}

View file

@ -1,5 +1,5 @@
use anyhow::anyhow;
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::select::Select;
@ -15,7 +15,7 @@ impl From<bool> for Opt {
}
impl Select {
pub fn close(&mut self, opt: impl Into<Opt>) -> bool {
pub fn close(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
if let Some(cb) = self.callback.take() {
_ = cb.send(if opt.submit { Ok(self.cursor) } else { Err(anyhow!("canceled")) });
@ -24,6 +24,6 @@ impl Select {
self.cursor = 0;
self.offset = 0;
self.visible = false;
true
render!();
}
}

View file

@ -1,7 +1,7 @@
use anyhow::{anyhow, Result};
use tokio::sync::oneshot;
use yazi_config::popup::SelectCfg;
use yazi_shared::{emit, event::Exec, term::Term, Layer};
use yazi_shared::{emit, event::Exec, render, term::Term, Layer};
use crate::select::Select;
@ -25,9 +25,9 @@ impl Select {
rx.await.unwrap_or_else(|_| Term::goodbye(|| false))
}
pub fn show(&mut self, opt: impl TryInto<Opt>) -> bool {
pub fn show(&mut self, opt: impl TryInto<Opt>) {
let Ok(opt) = opt.try_into() else {
return false;
return;
};
self.close(false);
@ -37,6 +37,6 @@ impl Select {
self.callback = Some(opt.tx);
self.visible = true;
true
render!();
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::{manager::Manager, tab::Tab, Step};
@ -20,7 +20,7 @@ where
}
impl Tab {
pub fn arrow(&mut self, opt: impl Into<Opt>) -> bool {
pub fn arrow(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
let ok = if opt.step.is_positive() {
self.current.next(opt.step)
@ -28,7 +28,7 @@ impl Tab {
self.current.prev(opt.step)
};
if !ok {
return false;
return;
}
// Visual selection
@ -42,6 +42,6 @@ impl Tab {
}
Manager::_hover(None);
true
render!();
}
}

View file

@ -11,17 +11,15 @@ impl From<&Exec> for Opt {
}
impl Tab {
pub fn back(&mut self, _: impl Into<Opt>) -> bool {
pub fn back(&mut self, _: impl Into<Opt>) {
if let Some(url) = self.backstack.shift_backward().cloned() {
self.cd(url);
}
false
}
pub fn forward(&mut self, _: impl Into<Opt>) -> bool {
pub fn forward(&mut self, _: impl Into<Opt>) {
if let Some(url) = self.backstack.shift_forward().cloned() {
self.cd(url);
}
false
}
}

View file

@ -3,7 +3,7 @@ use std::{mem, time::Duration};
use tokio::{fs, pin};
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
use yazi_config::popup::InputCfg;
use yazi_shared::{emit, event::Exec, fs::{expand_path, Url}, Debounce, InputError, Layer};
use yazi_shared::{emit, event::Exec, fs::{expand_path, Url}, render, Debounce, InputError, Layer};
use crate::{completion::Completion, input::Input, manager::Manager, tab::Tab};
@ -32,14 +32,14 @@ impl Tab {
emit!(Call(Exec::call("cd", vec![target.to_string()]).vec(), Layer::Manager));
}
pub fn cd(&mut self, opt: impl Into<Opt>) -> bool {
pub fn cd(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
if opt.interactive {
return self.cd_interactive();
}
if self.current.cwd == opt.target {
return false;
return;
}
// Take parent to history
@ -65,10 +65,10 @@ impl Tab {
}
Manager::_refresh();
true
render!();
}
fn cd_interactive(&mut self) -> bool {
fn cd_interactive(&mut self) {
tokio::spawn(async move {
let rx = Input::_show(InputCfg::cd());
@ -96,6 +96,5 @@ impl Tab {
}
}
});
false
}
}

View file

@ -1,6 +1,6 @@
use std::mem;
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::{manager::Manager, tab::Tab};
@ -13,9 +13,9 @@ impl From<&Exec> for Opt {
}
impl Tab {
pub fn enter(&mut self, _: impl Into<Opt>) -> bool {
pub fn enter(&mut self, _: impl Into<Opt>) {
let Some(hovered) = self.current.hovered().filter(|h| h.is_dir()).map(|h| h.url()) else {
return false;
return;
};
// Current
@ -35,6 +35,6 @@ impl Tab {
self.backstack.push(hovered);
Manager::_refresh();
true
render!();
}
}

View file

@ -42,7 +42,7 @@ impl Tab {
}
#[inline]
fn escape_select(&mut self) -> bool { self.select_all(Some(false)) }
fn escape_select(&mut self) -> bool { self.current.files.select_all(None) }
#[inline]
fn escape_filter(&mut self) -> bool {

View file

@ -84,18 +84,16 @@ impl Tab {
render!();
}
pub fn find_arrow(&mut self, opt: impl Into<ArrowOpt>) -> bool {
pub fn find_arrow(&mut self, opt: impl Into<ArrowOpt>) {
let Some(finder) = &mut self.finder else {
return false;
return;
};
let b = finder.catchup(&self.current.files);
let step = if opt.into().prev {
finder.prev(&self.current.files, self.current.cursor, false)
render!(finder.catchup(&self.current.files));
if opt.into().prev {
finder.prev(&self.current.files, self.current.cursor, false).map(|s| self.arrow(s));
} else {
finder.next(&self.current.files, self.current.cursor, false)
};
b | step.is_some_and(|s| self.arrow(s))
finder.next(&self.current.files, self.current.cursor, false).map(|s| self.arrow(s));
}
}
}

View file

@ -1,6 +1,6 @@
use std::mem;
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::{manager::Manager, tab::Tab};
@ -13,7 +13,7 @@ impl From<&Exec> for Opt {
}
impl Tab {
pub fn leave(&mut self, _: impl Into<Opt>) -> bool {
pub fn leave(&mut self, _: impl Into<Opt>) {
let current = self
.current
.hovered()
@ -22,7 +22,7 @@ impl Tab {
.or_else(|| self.current.cwd.parent_url());
let Some(current) = current else {
return false;
return;
};
// Parent
@ -44,6 +44,6 @@ impl Tab {
self.backstack.push(current);
Manager::_refresh();
true
render!();
}
}

View file

@ -1,6 +1,6 @@
use anyhow::anyhow;
use yazi_plugin::utils::PreviewLock;
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::tab::Tab;
@ -17,20 +17,20 @@ impl TryFrom<&Exec> for Opt {
}
impl Tab {
pub fn preview(&mut self, opt: impl TryInto<Opt>) -> bool {
pub fn preview(&mut self, opt: impl TryInto<Opt>) {
let Some(hovered) = self.current.hovered().map(|h| &h.url) else {
return self.preview.reset();
return render!(self.preview.reset());
};
let Ok(opt) = opt.try_into() else {
return false;
return;
};
if hovered != &opt.lock.url {
return false;
return;
}
self.preview.lock = Some(opt.lock);
true
render!();
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::{emit, event::Exec, fs::{expand_path, File, FilesOp, Url}, Layer};
use yazi_shared::{emit, event::Exec, fs::{expand_path, File, FilesOp, Url}, render, Layer};
use crate::{manager::Manager, tab::Tab};
@ -26,16 +26,15 @@ impl Tab {
emit!(Call(Exec::call("reveal", vec![target.to_string()]).vec(), Layer::Manager));
}
pub fn reveal(&mut self, opt: impl Into<Opt>) -> bool {
pub fn reveal(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
let Some(parent) = opt.target.parent_url() else {
return false;
return;
};
let b = self.cd(parent.clone());
self.cd(parent.clone());
FilesOp::Creating(parent, vec![File::from_dummy(opt.target.clone())]).emit();
Manager::_hover(Some(opt.target));
b
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::tab::Tab;
@ -22,14 +22,13 @@ impl From<Option<bool>> for Opt {
}
impl Tab {
pub fn select(&mut self, opt: impl Into<Opt>) -> bool {
pub fn select(&mut self, opt: impl Into<Opt>) {
if let Some(u) = self.current.hovered().map(|h| h.url()) {
return self.current.files.select(&u, opt.into().state);
render!(self.current.files.select(&u, opt.into().state));
}
false
}
pub fn select_all(&mut self, opt: impl Into<Opt>) -> bool {
self.current.files.select_all(opt.into().state)
pub fn select_all(&mut self, opt: impl Into<Opt>) {
render!(self.current.files.select_all(opt.into().state));
}
}

View file

@ -1,6 +1,6 @@
use std::collections::BTreeSet;
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::tab::{Mode, Tab};
@ -13,7 +13,7 @@ impl From<&Exec> for Opt {
}
impl Tab {
pub fn visual_mode(&mut self, opt: impl Into<Opt>) -> bool {
pub fn visual_mode(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
let idx = self.current.cursor;
@ -22,6 +22,6 @@ impl Tab {
} else {
self.mode = Mode::Select(idx, BTreeSet::from([idx]));
};
true
render!();
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::tasks::Tasks;
@ -14,23 +14,28 @@ impl From<&Exec> for Opt {
impl Tasks {
#[allow(clippy::should_implement_trait)]
fn next(&mut self) -> bool {
fn next(&mut self) {
let limit = Self::limit().min(self.len());
let old = self.cursor;
self.cursor = limit.saturating_sub(1).min(self.cursor + 1);
old != self.cursor
render!(old != self.cursor);
}
fn prev(&mut self) -> bool {
fn prev(&mut self) {
let old = self.cursor;
self.cursor = self.cursor.saturating_sub(1);
old != self.cursor
render!(old != self.cursor);
}
pub fn arrow(&mut self, opt: impl Into<Opt>) -> bool {
pub fn arrow(&mut self, opt: impl Into<Opt>) {
let opt = opt.into() as Opt;
if opt.step > 0 { self.next() } else { self.prev() }
if opt.step > 0 {
self.next();
} else {
self.prev();
}
}
}

View file

@ -1,16 +1,16 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::tasks::Tasks;
impl Tasks {
pub fn cancel(&mut self, _: &Exec) -> bool {
pub fn cancel(&mut self, _: &Exec) {
let id = self.scheduler.running.read().get_id(self.cursor);
if id.map(|id| self.scheduler.cancel(id)) != Some(true) {
return false;
return;
}
let len = self.scheduler.running.read().len();
self.cursor = self.cursor.min(len.saturating_sub(1));
true
render!();
}
}

View file

@ -8,9 +8,9 @@ use yazi_shared::{event::Exec, term::Term, Defer};
use crate::tasks::Tasks;
impl Tasks {
pub fn inspect(&self, _: &Exec) -> bool {
pub fn inspect(&self, _: &Exec) {
let Some(id) = self.scheduler.running.read().get_id(self.cursor) else {
return false;
return;
};
let scheduler = self.scheduler.clone();
@ -66,6 +66,5 @@ impl Tasks {
stdin.read(&mut quit).await.ok();
}
});
false
}
}

View file

@ -22,10 +22,9 @@ impl Tasks {
emit!(Call(Exec::call("open", vec![]).with_data(Opt { targets, opener }).vec(), Layer::Tasks));
}
pub fn open(&mut self, opt: impl TryInto<Opt>) -> bool {
pub fn open(&mut self, opt: impl TryInto<Opt>) {
if let Ok(opt) = opt.try_into() {
self.file_open_with(&opt.opener, &opt.targets);
}
false
}
}

View file

@ -1,4 +1,4 @@
use yazi_shared::event::Exec;
use yazi_shared::{event::Exec, render};
use crate::tasks::Tasks;
@ -12,8 +12,8 @@ impl From<()> for Opt {
}
impl Tasks {
pub fn toggle(&mut self, _: impl Into<Opt>) -> bool {
pub fn toggle(&mut self, _: impl Into<Opt>) {
self.visible = !self.visible;
true
render!();
}
}

View file

@ -1,5 +1,5 @@
use anyhow::anyhow;
use yazi_shared::{emit, event::Exec, Layer};
use yazi_shared::{emit, event::Exec, render, Layer};
use crate::tasks::{Tasks, TasksProgress};
@ -20,12 +20,12 @@ impl Tasks {
emit!(Call(Exec::call("update", vec![]).with_data(Opt { progress }).vec(), Layer::Tasks));
}
pub fn update(&mut self, opt: impl TryInto<Opt>) -> bool {
pub fn update(&mut self, opt: impl TryInto<Opt>) {
let Ok(opt) = opt.try_into() else {
return false;
return;
};
self.progress = opt.progress;
true
render!();
}
}

View file

@ -171,7 +171,7 @@ impl<'a> Executor<'a> {
b"tasks_show" => self.app.cx.tasks.toggle(()),
// Help
b"help" => self.app.cx.help.toggle(Layer::Manager),
_ => false,
_ => {}
}
}
@ -198,7 +198,7 @@ impl<'a> Executor<'a> {
match exec.cmd.as_str() {
"help" => self.app.cx.help.toggle(Layer::Tasks),
_ => false,
_ => {}
}
}
@ -217,7 +217,7 @@ impl<'a> Executor<'a> {
match exec.cmd.as_str() {
"help" => self.app.cx.help.toggle(Layer::Select),
_ => false,
_ => {}
}
}
@ -264,14 +264,12 @@ impl<'a> Executor<'a> {
match exec.cmd.as_str() {
"help" => self.app.cx.help.toggle(Layer::Input),
_ => false,
_ => {}
}
}
InputMode::Insert => {
on!(backspace);
on!(kill);
false
}
}
}