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

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

Open
wants to merge 46 commits into
base: master
Choose a base branch
from

Conversation

nik-rev
Copy link
Contributor

@nik-rev nik-rev commented Feb 17, 2025

The recently added File Explorer (#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 nik-rev marked this pull request as ready for review February 18, 2025 12:23
@nik-rev
Copy link
Contributor Author

nik-rev commented Feb 18, 2025

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

@CraigglesO
Copy link

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.

@darshanCommits
Copy link
Contributor

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.

@nik-rev
Copy link
Contributor Author

nik-rev commented Feb 18, 2025

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

@Bykow
Copy link

Bykow commented Feb 19, 2025

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

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

@nik-rev
Copy link
Contributor Author

nik-rev commented Feb 19, 2025

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: #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 nik-rev force-pushed the powerful-file-explorer branch from 49ccb6c to 674afbf Compare February 22, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants