-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort files in file picker by access, modification and creation date #336
Conversation
I think it would be good to have an option to change sorting priority, this could be a default but I don't know which is better. What if other users search? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this locally, but normal files (without an lsp running for them) only seem to be updated when opening and closing the editor. Rust files for example show up at the top right after saving them.
helix-term/src/ui/mod.rs
Outdated
files.sort_by(|(_, time1), (_, time2)| time1.cmp(time2)); | ||
|
||
let files = files.into_iter().map(|(path, _)| path).collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we collect into two vec using unzip
. Then, zip
it into an iterator and use sort_by_key
from the second iterator. So with this method we can remove the map
and collect
to files. What do you think?
Both methods collect twice, but the one I suggested collects beforehand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you sort an iterator though? I was sure that the methods are not available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, as a side note, I think this approach is a bit easier to read, but I'll let others chime in to decide.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait no, sorry. Don't zip
the iterator but just sort using the slice. Both approach seemed similar to me with the one I suggested taking less lines of code.
Also, both approach I will recommend using sort_by_key
rather than sort_by
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, now we can use sort_by_key
. Done.
Definitely a fan of this. I have a related feature I'd like to implement that I think will complement this: sorting open buffers in the @archseer also mentioned the possibility of merging the |
Merging space-f and space-b is something I've been thinking about too. It's unnecessary cognitive overload to think where the particular file can be opened from - if it's outside the cwd then you'd have to use the buffer picker else the file picker works fine. Definitely a quality of life improvement. |
The other idea I have is sort of |
files.collect() | ||
} else { | ||
const MAX: usize = 8192; | ||
files.take(MAX).collect() | ||
}; | ||
|
||
files.sort_by_key(|file| file.1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this makes it harder to pass input lazily later
…elix-editor#336) * Sort files in file picker by access date * Fallback file time to modified then created then UNIX_EPOCH * Use `sort_by_key` * Refactor
So this might not be very optimized but it's a big quality of life improvement. I use file picker a lot and sometimes I just want to see what I edited last without having to remember the exact filename. I tested this change on a quiet big repository - https://fuchsia.googlesource.com/fuchsia/ and the additional time to sort the entries was negligible even in debug mode.
I'm ok not to push it either if that will be the general consensus.
EDIT:
Actually meant access time not modification time