helix
helix copied to clipboard
Find file (space .)
Based on doom emacs find-file but also wanted to show an alternative to file explorer #2377.
@cossonleo this is what I mean, just got some motivation to do a draft to show you what I meant, but maybe this complement the tree explorer, this is more of a per directory navigation like :o <complete>
but with a picker / on steriods.
Still missing some basic stuff that I wanted to see
- [x] recurse find file
- [x] edit new file
- [x] current dir prompt
- [x] backspace navigate to upper directory
- [x] file metadata (most of the code is stolen from exa)
- [ ] add
format_fn
back to preview like shown as in image
Things not gonna be done in this pull request since they need more thoughts and can be done in separate pull request I believe
- prompt and results truncation in case it is too long
- file color or prompt color, tweaking it requires changing the how rendering is handled
- utf-8 file handling, I bet if CJK characters shows up in filename it's gonna look weird, but it's not gonna appear now
- ignore permission and size matches on search terms
Compared to doom emacs
The code seemed kinda hard to read now, might need some cleanup. Also, some code are stolen without much changes, didn't really go and tweak it to make it look nice (and count the characters) since the rendering may change later once we add color.
It's not clear to me what this is, it's showing a list of files? The idea is that it allows you to open directories?
It's not clear to me what this is, it's showing a list of files? The idea is that it allows you to open directories?
Yes, it's like ls
and you can easily change between directory. When you press enter you will open the file or directory (and directory it will show the same picker but different directory, if you press backspace it will go one directory backwards.
So it is more of like :o file
but it starts from the currently editing file directory and user can easily navigate between directory without keep pressing tab. This is very useful when user want to create a file on the same directory as the file they are currently editing.
Hi !
In neovim with the Telescope plugin, there is a file picker that I think is quite handy. You do not open directories, you just fuzzy find in the whole directory tree, recursively
Maybe this implementation could go in this direction ?
Isn't this already the default behavior of space f
?
Woops, yup I'm dumb sorry about that
https://github.com/helix-editor/helix/pull/2377 has added filter feature.
Is explore's list style + filter + back to parent directory with 'b' key
similar to this?
@pickfire
Is explore's list style + filter + back to parent directory with 'b' key similar to this?
Yes, so this is more like it's always in insert mode. In other terms, more like file picker, but per directory. The main benefit I see for this currently is sometimes I want to quickly edit new file on the same directory, I can just space . <filename> <enter>
, this is even more useful when you are editing files outside of a project, like ~/.config/helix/config.toml
(for me it's ~/usr/led/2022.ledger
and switch to ~/usr/led/main.ledger
, I don't know any good way to switch file on the same directory).
I tried the file tree, doesn't seemed to work like what I expected. I tried
-
space e
-
f
-
.md
, it does search instantly -
<enter>
, search results seemed to be gone - I cannot select, I expected the find to be able to press escape or enter to finish filter and continue press jk, but no
Also, behavior for file tree I find it weird, I don't quite know how to use it, have to try it a couple of times to figure out the behavior, for the find file in doom emacs, although I never used it before, I can easily get used to it in no time.
4. `<enter>`, search results seemed to be gone 5. I cannot select, I expected the find to be able to press escape or enter to finish filter and continue press jk, but no
You type <Tab>
or <ctrl-j>
directly instead of enter
.
I have optimized default item selected.
I usually use the file tree to read the code of large projects.
Although not done yet but should be good for review now given that most of the functionality is in place, the only big thing left is file metadata.
https://github.com/ogham/exa/issues/851 seemed like it would be good if exa could have exported some stuff as library rather than copy pasting code from exa. Not sure what @ariasuni think, just sharing one use case.
Well, as said in the issue, I don’t think it’s likely that exa will ever have the listed features as library. I don’t think we’re doing that in the most efficient way, and the code is quite tied to exa’s internal as far as I know. Actually, the other way round, I would be happy to use one such library in exa if it existed and was more ergonomic/performant than what we do right now.
Not sure how old the screenshot is, but I can see the k
s at the end of each line in the picker being highlighted, presumably because they match the k
in the search term. Could you limit the highlighting to just the path?
Not sure how old the screenshot is, but I can see the ks at the end of each line in the picker being highlighted, presumably because they match the k in the search term. Could you limit the highlighting to just the path?
I wanted to do that but that requires changing how the current rendering works, probably need to duplicate quite some stuff.
The only thing I'd say this was missing after playing with the explorer in the other pr is instead of 'no files found' when hovering a directory, it should show the directory contents.
But other than that, nice and very handy
I know it will probably be out of scope for this pr (or for the editor itself) but maybe in a future this popup can provide a minimal file manage capabilities as well. Like create a file/folder, delete file/folder and rename file/folder (move), I think it can be really cool
The only thing I'd say this was missing after playing with the explorer in the other pr is instead of 'no files found' when hovering a directory, it should show the directory contents.
Interesting, never thought of that.
With directory, but now the code seemed even worse, I think a cleanup is definitely needed.
I am thinking of adding two lines to the top to align the start of directory so when user navigate back and forth directory they won't feel like the position keep switching, also it needs some memoization if they enter the directory to not read the stuff twice, I feel bad that the quick implementation to try this out I just put the output as string.
┌─────────────────────────────────────────────────┐┌──────────────────────────────────────────────────┐
│ helix-term/src/ 13/13 ││ │
│─────────────────────────────────────────────────││ │
│ > ui/ drwxr-xr-x - ││ spinner.rs .rw-r--r-- 1.7k │
│ args.rs .rw-r--r-- 3.5k ││ text.rs .rw-r--r-- 1.9k │
│ commands/ drwxr-xr-x - ││ completion.rs .rw-r--r-- 16.0k │
│ config.rs .rw-r--r-- 2.9k ││ info.rs .rw-r--r-- 1.5k │
│ health.rs .rw-r--r-- 8.5k ││ popup.rs .rw-r--r-- 6.4k │
│ keymap/ drwxr-xr-x - ││ picker.rs .rw-r--r-- 38.0k │
│ lib.rs .rw-r--r-- 434 ││ editor.rs .rw-r--r-- 52.8k │
│ compositor.rs .rw-r--r-- 8.9k ││ markdown.rs .rw-r--r-- 12.4k │
│ job.rs .rw-r--r-- 2.7k ││ mod.rs .rw-r--r-- 15.3k │
│ main.rs .rw-r--r-- 3.6k ││ prompt.rs .rw-r--r-- 22.3k │
│ application.rs .rw-r--r-- 31.7k ││ │
│ commands.rs .rw-r--r-- 153.3k ││ │
│ keymap.rs .rw-r--r-- 17.1k ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
│ ││ │
└─────────────────────────────────────────────────┘└──────────────────────────────────────────────────┘
Not quite sure what I want to put up there in the empty space preview. @cossonleo @Termina94 any opinion on this?
I think I probably need to create helix-view/src/directory.rs
and dump the metadata and preview stuff there, and separate out the rendering logic.
And one thing here to note is that when user type in something to search but the file isn't present, then they press enter, it will create (open without save) that file, not sure how to make this feature more discoverable, with this user can easily create a file within the same directory as the opened file.
Not quite sure what I want to put up there in the empty space preview.
What about the absolute file path?
And one thing here to note is that when user type in something to search but the file isn't present, then they press enter, it will create (open without save) that file, not sure how to make this feature more discoverable, with this user can easily create a file within the same directory as the opened file.
If the file doesn't exist, you could have the default selected suggestion be a prompt to create the file, something like:
┌─────────────────────────────────────────────────┐┌──────────────────────────────────────────────────┐
│ helix-term/src/new.rs 13/13 ││ │
│─────────────────────────────────────────────────││ │
│ > create `new.rs` .rw-r--r-- - || |
I'd highlight the create prompt a different colour and I don't know what to put as the permissions, just whatever it would be by default if Helix created it. As for the preview you could just put <empty>
or just leave it blank.
If the file doesn't exist, you could have the default selected suggestion be a prompt to create the file, something like:
Nice idea, or maybe we can put that to the right side?
┌─────────────────────────────────────────────────┐┌──────────────────────────────────────────────────┐
│ helix-term/src/new.rs 13/13 ││ <edit new file> │
│─────────────────────────────────────────────────││ │
│ ││ │
What about the absolute file path?
It works but is redundant with the information on the prompt, I wonder if anything is useful for users browsing directory, I can think of a couple of extra stuff:
- 1 empty line, but seemed weird
┌─────────────────────────────────────────────────┐┌──────────────────────────────────────────────────┐
│ helix-term/src/new.rs 13/13 ││ <edit new file> │
│─────────────────────────────────────────────────││──────────────────────────────────────────────────│
│ ││ │
- maybe even omit the line?
┌─────────────────────────────────────────────────┐
│ helix-term/src/new.rs 13/13 │
│─────────────────────────────────────────────────│┌──────────────────────────────────────────────────┐
│ ││ │
-
show some stats, like how many files, how large is it, how many errors
-
show help keys, seemed weird to put here but works too
@lazytanuki @pickfire hi, this thread is pretty long so I did not read all the discussion, but I really want to mention this nvim plugin which seems to me the gold standard of file pickers (and we probably may learn something from them). It can do all sorts of stuff including moving, copying and deleting files. https://github.com/nvim-neo-tree/neo-tree.nvim
I've checked out this PR, built it, ran and find it quite good in terms of how it looks like, but there is a minor problem (bug): space . then start pressing backspace a few times... I get
helix on find-file via ⚙️ v1.61.0 took 6m11s
✦ 72% at 20:02:48 ❯ cargo run --release
Finished release [optimized] target(s) in 0.34s
Running `target/release/hx`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', helix-term/src/ui/picker.rs:565:61
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
when I try to backspace upper than my home directory (home/user) and upper. I think cases where directory does not exist should be handled more gracefully than panic on unwrap.
@adsick Thanks, looks like that was due to broken link on my machine, I fixed that.
Rebased the PR but looks like @sudormrfbin changes to remove format_fn
from FilePicker
removed the format, so I guess we need to add it back?
Will this pr be updated in the future?
Yes, but lately I haven't have time to work on this yet. I will probably do ctrl-r %
first as an easier temporary access to current directory.