mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Fix sorting not working and apply the suggested changes
This commit is contained in:
parent
8a9b7279f8
commit
f2976400f6
4 changed files with 18 additions and 31 deletions
|
|
@ -80,11 +80,7 @@ impl FilesSorter {
|
|||
if self.reverse { ordering.reverse() } else { ordering }
|
||||
});
|
||||
|
||||
let mut new = Vec::with_capacity(indices.len());
|
||||
for i in indices {
|
||||
new.push(mem::take(&mut items[i]));
|
||||
}
|
||||
*items = new;
|
||||
*items = indices.into_iter().map(|i| mem::take(&mut items[i])).collect();
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::str::FromStr;
|
|||
use yazi_config::{keymap::{Control, Key}, KEYMAP};
|
||||
use yazi_shared::{event::Cmd, render, Layer};
|
||||
|
||||
use crate::which::Which;
|
||||
use crate::which::{Which, WhichSorter};
|
||||
|
||||
pub struct Opt {
|
||||
cands: Vec<Control>,
|
||||
|
|
@ -52,7 +52,7 @@ impl Which {
|
|||
.map(|c| c.into())
|
||||
.collect();
|
||||
|
||||
self.sorter().sort(&mut self.cands);
|
||||
WhichSorter::default().sort(&mut self.cands);
|
||||
self.visible = true;
|
||||
self.silent = false;
|
||||
render!();
|
||||
|
|
|
|||
|
|
@ -1,15 +1,25 @@
|
|||
use std::{borrow::Cow, mem};
|
||||
|
||||
use yazi_config::{keymap::ControlCow, which::SortBy};
|
||||
use yazi_config::{keymap::ControlCow, which::SortBy, WHICH};
|
||||
use yazi_shared::natsort;
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialEq)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct WhichSorter {
|
||||
pub by: SortBy,
|
||||
pub sensitive: bool,
|
||||
pub reverse: bool,
|
||||
}
|
||||
|
||||
impl Default for WhichSorter {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
by: WHICH.sort_by,
|
||||
sensitive: WHICH.sort_sensitive,
|
||||
reverse: WHICH.sort_reverse,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WhichSorter {
|
||||
pub(super) fn sort(&self, items: &mut Vec<ControlCow>) {
|
||||
if self.by == SortBy::None || items.is_empty() {
|
||||
|
|
@ -32,10 +42,6 @@ impl WhichSorter {
|
|||
if self.reverse { ordering.reverse() } else { ordering }
|
||||
});
|
||||
|
||||
let mut new = Vec::with_capacity(indices.len());
|
||||
for i in indices {
|
||||
new.push(mem::take(&mut items[i]));
|
||||
}
|
||||
*items = new;
|
||||
*items = indices.into_iter().map(|i| mem::take(&mut items[i])).collect();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,12 @@
|
|||
use yazi_config::{keymap::{ControlCow, Key}, which::SortBy};
|
||||
use yazi_config::keymap::{ControlCow, Key};
|
||||
use yazi_shared::{emit, render, Layer};
|
||||
|
||||
use super::WhichSorter;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
#[derive(Default)]
|
||||
pub struct Which {
|
||||
pub(super) layer: Layer,
|
||||
pub times: usize,
|
||||
pub cands: Vec<ControlCow>,
|
||||
|
||||
// Sorting
|
||||
sort_by: SortBy,
|
||||
sort_sensitive: bool,
|
||||
sort_reverse: bool,
|
||||
|
||||
// Visibility
|
||||
pub visible: bool,
|
||||
pub silent: bool,
|
||||
|
|
@ -38,14 +31,6 @@ impl Which {
|
|||
true
|
||||
}
|
||||
|
||||
pub(super) fn sorter(&self) -> WhichSorter {
|
||||
WhichSorter {
|
||||
by: self.sort_by,
|
||||
sensitive: self.sort_sensitive,
|
||||
reverse: self.sort_reverse,
|
||||
}
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
self.times = 0;
|
||||
self.cands.clear();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue