@@ -156,22 +156,23 @@ impl PluginState {
156156
157157 /// Combine sessions and zoxide directories for display
158158 fn combined_items ( & self ) -> Vec < SessionItem > {
159- let mut sessions: Vec < SessionItem > = Vec :: new ( ) ;
159+ let mut existing_sessions: Vec < SessionItem > = Vec :: new ( ) ;
160+ let mut resurrectable_sessions: Vec < SessionItem > = Vec :: new ( ) ;
160161 let mut directories: Vec < SessionItem > = Vec :: new ( ) ;
161162 let mut added_session_names = HashSet :: new ( ) ;
162163
163164 // First, collect existing sessions that match zoxide directories (including incremented ones)
164165 for session in self . session_manager . sessions ( ) {
165166 if let Some ( zoxide_dir) = self . find_matching_zoxide_dir ( & session. name ) {
166- sessions . push ( SessionItem :: ExistingSession {
167+ existing_sessions . push ( SessionItem :: ExistingSession {
167168 name : session. name . clone ( ) ,
168169 directory : zoxide_dir. directory . clone ( ) ,
169170 is_current : session. is_current_session ,
170171 } ) ;
171172 added_session_names. insert ( session. name . clone ( ) ) ;
172173 } else if self . config . show_all_sessions {
173174 // Session didn't match any zoxide dir, but show_all_sessions is enabled
174- sessions . push ( SessionItem :: ExistingSession {
175+ existing_sessions . push ( SessionItem :: ExistingSession {
175176 name : session. name . clone ( ) ,
176177 directory : String :: new ( ) ,
177178 is_current : session. is_current_session ,
@@ -190,7 +191,7 @@ impl PluginState {
190191
191192 let matches_zoxide = self . find_matching_zoxide_dir ( name) . is_some ( ) ;
192193 if matches_zoxide || self . config . show_all_sessions {
193- sessions . push ( SessionItem :: ResurrectableSession {
194+ resurrectable_sessions . push ( SessionItem :: ResurrectableSession {
194195 name : name. clone ( ) ,
195196 duration : * duration,
196197 } ) ;
@@ -206,24 +207,38 @@ impl PluginState {
206207 } ) ;
207208 }
208209
209- // Sort sessions based on config
210+ // Sort existing sessions based on config
210211 match self . config . sort_order {
211212 SortOrder :: Mru => {
212213 // Sort by MRU timestamp (descending - most recent first)
213- sessions . sort_by ( |a, b| {
214+ existing_sessions . sort_by ( |a, b| {
214215 let ts_a = self . session_manager . get_mru_rank ( a. name ( ) ) ;
215216 let ts_b = self . session_manager . get_mru_rank ( b. name ( ) ) ;
216217 ts_b. cmp ( & ts_a) // Descending order
217218 } ) ;
218219 }
219220 SortOrder :: Alphabetical => {
220221 // Sort alphabetically by name (case-insensitive)
221- sessions . sort_by_key ( |a| a. name ( ) . to_lowercase ( ) ) ;
222+ existing_sessions . sort_by_key ( |a| a. name ( ) . to_lowercase ( ) ) ;
222223 }
223224 }
224225
225- // Combine: sorted sessions first, then directories (already sorted by zoxide score)
226- let mut items = sessions;
226+ // Sort resurrectable sessions by age (most recently killed first = smallest duration)
227+ resurrectable_sessions. sort_by ( |a, b| {
228+ let dur_a = match a {
229+ SessionItem :: ResurrectableSession { duration, .. } => * duration,
230+ _ => std:: time:: Duration :: MAX ,
231+ } ;
232+ let dur_b = match b {
233+ SessionItem :: ResurrectableSession { duration, .. } => * duration,
234+ _ => std:: time:: Duration :: MAX ,
235+ } ;
236+ dur_a. cmp ( & dur_b) // Ascending order (smallest/most recent first)
237+ } ) ;
238+
239+ // Combine: existing sessions, then resurrectable, then directories
240+ let mut items = existing_sessions;
241+ items. append ( & mut resurrectable_sessions) ;
227242 items. append ( & mut directories) ;
228243 items
229244 }
0 commit comments