Skip to content
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

Find file (space .) #2412

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

pickfire
Copy link
Contributor

@pickfire pickfire commented May 5, 2022

Based on doom emacs find-file but also wanted to show an alternative to
file explorer #2377.

Screenshot_20220531_001520

@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

  • recurse find file
  • edit new file
  • current dir prompt
  • backspace navigate to upper directory
  • 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

Screenshot_20220506_005024

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.

@archseer
Copy link
Member

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?

@pickfire
Copy link
Contributor Author

pickfire commented May 11, 2022

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.

@lazytanuki
Copy link
Contributor

lazytanuki commented May 12, 2022

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
Peek 2022-05-12 15-47

Maybe this implementation could go in this direction ?

@archseer
Copy link
Member

Isn't this already the default behavior of space f?

@lazytanuki
Copy link
Contributor

Woops, yup I'm dumb sorry about that

@cossonleo
Copy link
Contributor

#2377 has added filter feature.
Is explore's list style + filter + back to parent directory with 'b' key similar to this?

@pickfire

@pickfire
Copy link
Contributor Author

pickfire commented May 12, 2022

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

  1. space e
  2. f
  3. .md, it does search instantly
  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

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.

@cossonleo
Copy link
Contributor

cossonleo commented May 12, 2022

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.

helix-term/src/commands.rs Outdated Show resolved Hide resolved
@the-mikedavis the-mikedavis added the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label May 18, 2022
.into_owned()
+ "/";
*picker.picker.prompt.prompt_mut() = Cow::Owned(prompt);
picker.picker.prompt.prompt_style_fn = Box::new(|theme| Some(theme.get("blue")));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this blue isn't working, I even tried palette.blue.

@pickfire pickfire marked this pull request as ready for review May 29, 2022 16:42
@pickfire
Copy link
Contributor Author

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.

@the-mikedavis the-mikedavis removed the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label May 29, 2022
@pickfire
Copy link
Contributor Author

ogham/exa#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.

@pickfire pickfire force-pushed the find-file branch 3 times, most recently from c00334c to 66bcd58 Compare May 30, 2022 17:07
@ariasuni
Copy link

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.

@n0s4
Copy link
Contributor

n0s4 commented May 30, 2022

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?

@pickfire
Copy link
Contributor Author

pickfire commented May 30, 2022

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.

@pickfire pickfire force-pushed the find-file branch 3 times, most recently from 8e9d3e5 to a5cf088 Compare June 1, 2022 10:40
@Termina94
Copy link
Contributor

Termina94 commented Jun 8, 2022

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

@souzaramon
Copy link

souzaramon commented Jun 8, 2022

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

@pickfire
Copy link
Contributor Author

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.

@pickfire
Copy link
Contributor Author

pickfire commented Jun 19, 2022

With directory, but now the code seemed even worse, I think a cleanup is definitely needed.

Screenshot_20220619_234148

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.

@n0s4
Copy link
Contributor

n0s4 commented Jun 19, 2022

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.

@pickfire
Copy link
Contributor Author

pickfire commented Jun 21, 2022

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

aikomastboom pushed a commit to aikomastboom/helix that referenced this pull request Jul 10, 2022
introduced helper mod to reduce duplicate code
@kirawi kirawi added A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Sep 13, 2022
@adsick
Copy link

adsick commented Sep 23, 2022

@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

@adsick
Copy link

adsick commented Sep 23, 2022

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.

@pickfire
Copy link
Contributor Author

pickfire commented Sep 28, 2022

@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?

Based on doom emacs find-file but also wanted to show an alternative to
file explorer helix-editor#2377.
@erasin
Copy link
Contributor

erasin commented Dec 12, 2022

Will this pr be updated in the future?

@pickfire
Copy link
Contributor Author

pickfire commented Jan 13, 2023

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.

@pascalkuthe pascalkuthe added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.