mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Some checks are pending
Cachix / Publish Flake (push) Waiting to run
Check / clippy (push) Waiting to run
Check / rustfmt (push) Waiting to run
Check / stylua (push) Waiting to run
Draft / build-unix (gcc-aarch64-linux-gnu, ubuntu-latest, aarch64-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (gcc-i686-linux-gnu, ubuntu-latest, i686-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (gcc-riscv64-linux-gnu, ubuntu-latest, riscv64gc-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (gcc-sparc64-linux-gnu, ubuntu-latest, sparc64-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (macos-latest, aarch64-apple-darwin) (push) Waiting to run
Draft / build-unix (macos-latest, x86_64-apple-darwin) (push) Waiting to run
Draft / build-unix (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Waiting to run
Draft / build-windows (windows-latest, aarch64-pc-windows-msvc) (push) Waiting to run
Draft / build-windows (windows-latest, x86_64-pc-windows-msvc) (push) Waiting to run
Draft / build-musl (aarch64-unknown-linux-musl) (push) Waiting to run
Draft / build-musl (x86_64-unknown-linux-musl) (push) Waiting to run
Draft / build-snap (amd64, ubuntu-latest) (push) Waiting to run
Draft / build-snap (arm64, ubuntu-24.04-arm) (push) Waiting to run
Draft / snap (push) Blocked by required conditions
Draft / draft (push) Blocked by required conditions
Draft / nightly (push) Blocked by required conditions
Test / test (macos-latest) (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
Test / test (windows-latest) (push) Waiting to run
67 lines
1.8 KiB
Rust
67 lines
1.8 KiB
Rust
use anyhow::Result;
|
|
use yazi_core::tab::Folder;
|
|
use yazi_fs::{FilesSorter, FolderStage};
|
|
use yazi_macro::{act, render, render_and, succ};
|
|
use yazi_parser::{mgr::SortForm, spark::SparkKind};
|
|
use yazi_shared::{Source, data::Data};
|
|
use yazi_shim::OptionExt;
|
|
|
|
use crate::{Actor, Ctx};
|
|
|
|
pub struct Sort;
|
|
|
|
impl Actor for Sort {
|
|
type Form = SortForm;
|
|
|
|
const NAME: &str = "sort";
|
|
|
|
fn act(cx: &mut Ctx, form: Self::Form) -> Result<Data> {
|
|
let pref = &mut cx.tab_mut().pref;
|
|
pref.sort_by = form.by.unwrap_or(pref.sort_by);
|
|
pref.sort_reverse = form.reverse.unwrap_or(pref.sort_reverse);
|
|
pref.sort_dir_first = form.dir_first.unwrap_or(pref.sort_dir_first);
|
|
pref.sort_sensitive = form.sensitive.unwrap_or(pref.sort_sensitive);
|
|
pref.sort_translit = form.translit.unwrap_or(pref.sort_translit);
|
|
pref.sort_fallback = form.fallback.unwrap_or(pref.sort_fallback);
|
|
|
|
let sorter = FilesSorter::from(&*pref);
|
|
let hovered = cx.hovered().map(|f| f.entry_key()).owned();
|
|
let apply = |f: &mut Folder| {
|
|
if f.stage == FolderStage::Loading {
|
|
render!();
|
|
false
|
|
} else {
|
|
f.entries.set_sorter(sorter);
|
|
render_and!(f.entries.catchup_revision())
|
|
}
|
|
};
|
|
|
|
// Apply to CWD and parent
|
|
if apply(cx.current_mut()) | cx.parent_mut().is_some_and(apply) {
|
|
act!(mgr:hover, cx)?;
|
|
act!(mgr:update_paged, cx)?;
|
|
cx.tasks.prework_sorted(&cx.mgr.tabs[cx.tab].current.entries);
|
|
}
|
|
|
|
// Apply to hovered
|
|
if let Some(h) = cx.hovered_folder_mut()
|
|
&& apply(h)
|
|
{
|
|
render!(h.repos(None));
|
|
act!(mgr:peek, cx, true)?;
|
|
} else if cx.hovered().map(|f| f.entry_key()) != hovered.as_ref().map(Into::into) {
|
|
act!(mgr:peek, cx)?;
|
|
act!(mgr:watch, cx)?;
|
|
}
|
|
|
|
succ!();
|
|
}
|
|
|
|
fn hook(cx: &Ctx, _: &Self::Form) -> Option<SparkKind> {
|
|
match cx.source() {
|
|
Source::Ind => Some(SparkKind::IndSort),
|
|
Source::Key => Some(SparkKind::KeySort),
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|