From 78b98a98c356b2846d902aa349b8474d8fa60cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20=C2=B7=20Misaki=20Masa?= Date: Sun, 10 Mar 2024 20:12:54 +0800 Subject: [PATCH] fix: use `BTreeSet` for selected files to maintain order (#799) --- yazi-core/src/tab/selected.rs | 6 +++--- yazi-fm/src/lives/selected.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/yazi-core/src/tab/selected.rs b/yazi-core/src/tab/selected.rs index 8e0f2117..375fe011 100644 --- a/yazi-core/src/tab/selected.rs +++ b/yazi-core/src/tab/selected.rs @@ -1,15 +1,15 @@ -use std::{collections::{HashMap, HashSet}, ops::Deref}; +use std::{collections::{BTreeSet, HashMap}, ops::Deref}; use yazi_shared::fs::{FilesOp, Url}; #[derive(Default)] pub struct Selected { - inner: HashSet, + inner: BTreeSet, parents: HashMap, } impl Deref for Selected { - type Target = HashSet; + type Target = BTreeSet; fn deref(&self) -> &Self::Target { &self.inner } } diff --git a/yazi-fm/src/lives/selected.rs b/yazi-fm/src/lives/selected.rs index 57f7e16e..4db92664 100644 --- a/yazi-fm/src/lives/selected.rs +++ b/yazi-fm/src/lives/selected.rs @@ -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 yazi_plugin::{bindings::Cast, url::Url}; @@ -7,18 +7,18 @@ use super::{Iter, SCOPE}; #[derive(Clone, Copy)] pub(super) struct Selected { - inner: *const HashSet, + inner: *const BTreeSet, } impl Deref for Selected { - type Target = HashSet; + type Target = BTreeSet; fn deref(&self) -> &Self::Target { self.inner() } } impl Selected { #[inline] - pub(super) fn make(inner: &HashSet) -> mlua::Result> { + pub(super) fn make(inner: &BTreeSet) -> mlua::Result> { SCOPE.create_any_userdata(Self { inner }) } @@ -45,5 +45,5 @@ impl Selected { } #[inline] - fn inner(&self) -> &'static HashSet { unsafe { &*self.inner } } + fn inner(&self) -> &'static BTreeSet { unsafe { &*self.inner } } }