11use anyhow:: Result ;
2- use yazi_macro:: { act, succ} ;
2+ use yazi_core:: tab:: Folder ;
3+ use yazi_fs:: { FilesSorter , FolderStage } ;
4+ use yazi_macro:: { act, render, render_and, succ} ;
35use yazi_parser:: mgr:: SortOpt ;
46use yazi_shared:: event:: Data ;
57
@@ -13,25 +15,44 @@ impl Actor for Sort {
1315 const NAME : & str = "sort" ;
1416
1517 fn act ( cx : & mut Ctx , opt : Self :: Options ) -> Result < Data > {
16- let mut new = cx. tab ( ) . pref . clone ( ) ;
17- new. sort_by = opt. by . unwrap_or ( new. sort_by ) ;
18- new. sort_reverse = opt. reverse . unwrap_or ( new. sort_reverse ) ;
19- new. sort_dir_first = opt. dir_first . unwrap_or ( new. sort_dir_first ) ;
20- new. sort_sensitive = opt. sensitive . unwrap_or ( new. sort_sensitive ) ;
21- new. sort_translit = opt. translit . unwrap_or ( new. sort_translit ) ;
22-
23- if new == cx. tab ( ) . pref {
24- succ ! ( ) ;
18+ let pref = & mut cx. tab_mut ( ) . pref ;
19+ pref. sort_by = opt. by . unwrap_or ( pref. sort_by ) ;
20+ pref. sort_reverse = opt. reverse . unwrap_or ( pref. sort_reverse ) ;
21+ pref. sort_dir_first = opt. dir_first . unwrap_or ( pref. sort_dir_first ) ;
22+ pref. sort_sensitive = opt. sensitive . unwrap_or ( pref. sort_sensitive ) ;
23+ pref. sort_translit = opt. translit . unwrap_or ( pref. sort_translit ) ;
24+
25+ let sorter = FilesSorter :: from ( & * pref) ;
26+ let hovered = cx. hovered ( ) . map ( |f| f. urn_owned ( ) ) ;
27+ let apply = |f : & mut Folder | {
28+ if f. stage == FolderStage :: Loading {
29+ render ! ( ) ;
30+ false
31+ } else {
32+ f. files . set_sorter ( sorter) ;
33+ render_and ! ( f. files. catchup_revision( ) )
34+ }
35+ } ;
36+
37+ // Apply to CWD and parent
38+ if let ( a, Some ( b) ) = ( apply ( cx. current_mut ( ) ) , cx. parent_mut ( ) . map ( apply) )
39+ && ( a | b)
40+ {
41+ act ! ( mgr: hover, cx) ?;
42+ act ! ( mgr: update_paged, cx) ?;
43+ cx. tasks . prework_sorted ( & cx. mgr . tabs [ cx. tab ] . current . files ) ;
2544 }
2645
27- cx. tab_mut ( ) . pref = new;
28- cx. tab_mut ( ) . apply_files_attrs ( ) ;
29- act ! ( mgr: hover, cx) ?;
30-
31- cx. tasks . prework_sorted ( & cx. mgr . tabs [ cx. tab ] . current . files ) ;
32- act ! ( mgr: peek, cx) ?;
33- act ! ( mgr: watch, cx) ?;
34- act ! ( mgr: update_paged, cx) ?;
46+ // Apply to hovered
47+ if let Some ( h) = cx. hovered_folder_mut ( )
48+ && apply ( h)
49+ {
50+ render ! ( h. repos( None ) ) ;
51+ act ! ( mgr: peek, cx, true ) ?;
52+ } else if hovered. as_deref ( ) != cx. hovered ( ) . map ( |f| f. urn ( ) ) {
53+ act ! ( mgr: peek, cx) ?;
54+ act ! ( mgr: watch, cx) ?;
55+ }
3556
3657 succ ! ( ) ;
3758 }
0 commit comments