helix icon indicating copy to clipboard operation
helix copied to clipboard

feat: Create, Delete, Copy, Move, Rename files in the File Explorer

Open nik-rev opened this issue 9 months ago • 13 comments

The recently added File Explorer (https://github.com/helix-editor/helix/pull/11285) is awesome, but it's missing a couple of features which I'd classify as nice-to-have (you can already delete / move / create etc files in Helix, but it's more ergonomic to be able to do that right from the picker instead of having to close it, type the command in cmd mode (:) and then going back to the picker)

Features this PR adds:

  • New API that allows passing custom key handlers when creating new Pickers. This'll also be nice for the plugin ecosystem
  • Implement the following functions inside the File Explorer
    • Create new files and directories
    • Delete files and directories
    • Move files and directories
    • Rename files and directories
    • Copy files
    • Yank paths to a register
  • Documentation
  • The user is always prompted for confirmation before doing any destructive action.

Keymapping

Key Description
Alt-m Move selected file or directory
Alt-n Create a new file or directory
Alt-d Delete the selected file or directory
Alt-c Copy the selected file
Alt-y Yank the path to the selected file or directory

Implementation

Each Picker now holds a map of KeyEvent => KeyHandler where KeyHandler is some function. The function has access to the currently selected item in the Picker and the Picker's editor_data

In Component::handle_event implementation for the Picker we first of all check if there is a KeyHandler registered for a specific KeyEvent. If yes then we execute it.

nik-rev avatar Feb 17 '25 22:02 nik-rev

Sorry if this is ignorant, but would a paste be hard to implement as well?

What would that do?

Edit: The person who wrote that deleted their comment

Regardless, I would like to not add any more features to this PR aside from fixes since that would mean it is easier to review and has higher chance of being merged

nik-rev avatar Feb 18 '25 17:02 nik-rev

Sorry if this is ignorant, but would a paste be hard to implement as well?

What would that do?

Edit: The person who wrote that deleted their comment

Regardless, I would like to not add any more features to this PR aside from fixes since that would mean it is easier to review and has higher chance of being merged

This was me. Sorry, I read through the code and thought it would be a more straight forward way of copying a file, then navigating to an entirely new folder, then pasting. But the more I read it the more I realized it probably wouldn't be necessary or easy.

CraigglesO avatar Feb 18 '25 18:02 CraigglesO

Instead of keybingings, what about a custom parser for the file explorer so that

We can do cmds like mv, cp, mkdir right in the search. And being able to "select" using spacebar to make them $1

Like

  1. :rm
  2. Navigate the files.
  3. Press "space" to select and thus pass onto the :rm cmd.

what is the opinion on this.

kumawatdarshan avatar Feb 18 '25 18:02 kumawatdarshan

Instead of keybingings, what about a custom parser for the file explorer so that

We can do cmds like mv, cp, mkdir right in the search. And being able to "select" using spacebar to make them $1

Like

  1. :rm
  2. Navigate the files.
  3. Press "space" to select and thus pass onto the :rm cmd.

what is the opinion on this.

That sounds more complicated (I would like to keep the PR small) and less intuitive imo. The command mode seems more suitable for that

nik-rev avatar Feb 18 '25 23:02 nik-rev

Could it be possible to configure or use other key binds ?

Alt is commonly used in i3wm/swaywm as the modifier.

Bykow avatar Feb 19 '25 08:02 Bykow

Could it be possible to configure or use other key binds ?

Alt is commonly used in i3wm/swaywm as the modifier.

I also use Sway and I'll have to remap some of my keys as well to use this PR. The reason why I went with these is that they're mnemonics and the ctrl-* equivalents were taken. Helix also uses Alt-* keys elsewhere

The actual solution would be to allow the user to remap these keys. You currently are unable to remap keys for Component's handle_event and this is a known issue: https://github.com/helix-editor/helix/issues/5505

I believe @gabydd has a branch that would fix that, and allow you to remap keys that currently can't be remapped, which should also include this PR (with some changes). But that's a large refactor

nik-rev avatar Feb 19 '25 09:02 nik-rev

@nik-rev should these operations send the same LSP event discussed here?

https://github.com/helix-editor/helix/issues/8942

smartinellimarco avatar Feb 26 '25 19:02 smartinellimarco

@nik-rev should these operations send the same LSP event discussed here?

#8942

Yes, that's true.

nik-rev avatar Feb 26 '25 19:02 nik-rev

Using Editor::move_path instead of fs::rename now, which will alert language servers properly.

nik-rev avatar Feb 28 '25 14:02 nik-rev

the File Picker lists only files. I guess we just need something like joshuto or a new directory picker.

moqsien avatar Mar 02 '25 10:03 moqsien

This could include Alt-h or similar for showing the possible keymaps.

andradei avatar Mar 19 '25 21:03 andradei

This could include Alt-h or similar for showing the possible keymaps.

There's quite some code to add this and I'd like to see this in a different PR. Ideally we should have a Component to render a list of options

This would also be useful for https://github.com/helix-editor/helix/issues/12602#issue-2797572214

nik-rev avatar Mar 19 '25 23:03 nik-rev

IMO, for a file explorer, searching the open directory is an infrecuent enough operation to warrent the trade off of having a separate normal mode for the file explorer. This would make it easier to perform file operations since you don't have to press alt, but harder to search the open directory since you have to press i (or /) and <esc>.

Here's the discussion on adding normal mode for some pickers: https://github.com/helix-editor/helix/discussions/10599.

godalming123 avatar Apr 21 '25 09:04 godalming123

This is cool. May I suggest one more command - cd - in other words make current dir default for future invocations of file pickers.

yerlaser avatar Jul 16 '25 14:07 yerlaser

PR looks solid, what's holding it back from getting merged?

aryzing avatar Sep 03 '25 13:09 aryzing

I tried out your PR, and I have some thoughts.

  • Pretty much every operation as-implemented can apply to the file picker as well. I think for consistency both should have this functionality.
  • If at all possible, file operations should be tied to the helix undo-redo system, or have their own. Even with a confirmation, I could end up deleting a file or directory that I didn't have tracked in git, and lose it forever.
  • The UX for moving files still sucks, as you can't peek into subdirectories to get an idea of layout while moving a file, but it's a step up from anything else, so that's just me griping (Side-Note: I'd like to see the ability to view the contents of a directory while still in a higher level directory, perhaps with an Alt-Enter keybind to drop down the contents into the current picker, not for this PR of course)

As for the code side

  • There's surprisingly few amount of LOC changed, so consider me impressed!
  • There were a lot of warnings when building, that I'm unsure if they are related to this PR, but worth looking into.
  • I imagine the 58 commits, could be squashed in some way, but maybe you're keeping them for easier review? :shrug:
  • If I have time, I'll review the code and see if there's anything I'd change

PR looks solid, what's holding it back from getting merged?

Lack of review bandwidth from maintainers, and I imagine there are things the maintainers would do differently, and I know in a different PR I've seen maintainers wanting a solution for https://github.com/helix-editor/helix/issues/5505 before introducing new keybindings for components.

ryanabx avatar Nov 15 '25 20:11 ryanabx

Another unfortunate thing I thought of is that the alt keybindings might conflict with zellij, or other terminal multiplexers. That can't be helped though, and probably happens with other alt keybindings in helix too.

ryanabx avatar Nov 17 '25 20:11 ryanabx