fix: use BTreeSet for selected files to maintain order (#799)

This commit is contained in:
三咲雅 · Misaki Masa 2024-03-10 20:12:54 +08:00 committed by GitHub
parent b10f2de16d
commit 78b98a98c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -1,15 +1,15 @@
use std::{collections::{HashMap, HashSet}, ops::Deref}; use std::{collections::{BTreeSet, HashMap}, ops::Deref};
use yazi_shared::fs::{FilesOp, Url}; use yazi_shared::fs::{FilesOp, Url};
#[derive(Default)] #[derive(Default)]
pub struct Selected { pub struct Selected {
inner: HashSet<Url>, inner: BTreeSet<Url>,
parents: HashMap<Url, usize>, parents: HashMap<Url, usize>,
} }
impl Deref for Selected { impl Deref for Selected {
type Target = HashSet<Url>; type Target = BTreeSet<Url>;
fn deref(&self) -> &Self::Target { &self.inner } fn deref(&self) -> &Self::Target { &self.inner }
} }

View File

@ -1,4 +1,4 @@
use std::{collections::{hash_set, HashSet}, ops::Deref}; use std::{collections::{hash_set, BTreeSet}, ops::Deref};
use mlua::{AnyUserData, IntoLuaMulti, Lua, MetaMethod, UserDataMethods, UserDataRefMut}; use mlua::{AnyUserData, IntoLuaMulti, Lua, MetaMethod, UserDataMethods, UserDataRefMut};
use yazi_plugin::{bindings::Cast, url::Url}; use yazi_plugin::{bindings::Cast, url::Url};
@ -7,18 +7,18 @@ use super::{Iter, SCOPE};
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub(super) struct Selected { pub(super) struct Selected {
inner: *const HashSet<yazi_shared::fs::Url>, inner: *const BTreeSet<yazi_shared::fs::Url>,
} }
impl Deref for Selected { impl Deref for Selected {
type Target = HashSet<yazi_shared::fs::Url>; type Target = BTreeSet<yazi_shared::fs::Url>;
fn deref(&self) -> &Self::Target { self.inner() } fn deref(&self) -> &Self::Target { self.inner() }
} }
impl Selected { impl Selected {
#[inline] #[inline]
pub(super) fn make(inner: &HashSet<yazi_shared::fs::Url>) -> mlua::Result<AnyUserData<'static>> { pub(super) fn make(inner: &BTreeSet<yazi_shared::fs::Url>) -> mlua::Result<AnyUserData<'static>> {
SCOPE.create_any_userdata(Self { inner }) SCOPE.create_any_userdata(Self { inner })
} }
@ -45,5 +45,5 @@ impl Selected {
} }
#[inline] #[inline]
fn inner(&self) -> &'static HashSet<yazi_shared::fs::Url> { unsafe { &*self.inner } } fn inner(&self) -> &'static BTreeSet<yazi_shared::fs::Url> { unsafe { &*self.inner } }
} }