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

Show filename in prompt when deleting a file #827

Open
1 task done
cbr9 opened this issue Mar 18, 2024 · 3 comments
Open
1 task done

Show filename in prompt when deleting a file #827

cbr9 opened this issue Mar 18, 2024 · 3 comments
Labels
feature New feature request

Comments

@cbr9
Copy link

cbr9 commented Mar 18, 2024

Please describe the problem you're trying to solve

Hello, and thank you for creating yazi! Today I discovered it and ditched lf in favor of yazi :)

However, I have a request. I would like to see the name of the file I am about to delete, if it's just one, or even potentially a list of them if several are selected.

The point would be to avoid accidental deletions of important files

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

I'm not sure if delete_title can be a multiline string, or how that's rendered, but an idea would be to expose an extra variable, similar to lf's $fx or $fs. Then the prompt could be something like:

Delete the following files?
[...list of files]
(y/N)

Additional context

No response

@cbr9 cbr9 added the feature New feature request label Mar 18, 2024
@sxyazi
Copy link
Owner

sxyazi commented Mar 19, 2024

The current deletion prompt is an input box, which cannot include multi-line file list information in the title. I plan to add a separate confirm component to achieve this, it looks like:

CleanShot 2024-03-20 at 00 23 20

"Are you sure you want to move this file to the trash?" can be replaced with multi-line text. (Screenshot from neo-tree, a file manager plugin in neovim)

But I haven't had enough time to complete it, would you like to give it a try? - If you're interested, I'll provide more details on how to implement it ;)

@cbr9
Copy link
Author

cbr9 commented Mar 19, 2024

Sure, if I get some free time I can play around with it for a bit

@sxyazi
Copy link
Owner

sxyazi commented Mar 19, 2024

Thank you, here are some implementation details:

  1. Copy /yazi-core/src/select/ as /yazi-core/src/confirm/, which is a relatively simple module and can be a good starting point.

  2. Add pub confirm: Confirm below pub input:

    pub struct Ctx {
    pub manager: Manager,
    pub tasks: Tasks,
    pub select: Select,
    pub input: Input,
    pub help: Help,
    pub completion: Completion,
    pub which: Which,
    pub notify: Notify,
    }

  3. Add self.cx.confirm.visible below self.cx.input.visible in Root for rendering the Confirm component:

    yazi/yazi-fm/src/root.rs

    Lines 33 to 36 in 955e8f5

    if self.cx.input.visible {
    input::Input::new(self.cx).render(area, buf);
    }

  4. Add a new Confirm in Layer to indicate the layer level of this component, below Input:

    pub enum Layer {
    #[default]
    App,
    Manager,
    Tasks,
    Select,
    Input,
    Help,
    Completion,
    Which,
    }

  5. Add a new [confirm] section in keymap.toml to define key bindings (confirm, cancel) for Confirm component:

    [confirm]
    keymap = [
     	{ on = [ "<Esc>" ], run = "close", desc = "Cancel the confirm" },
     	{ on = [ "n" ],     run = "close", desc = "Cancel the confirm" },
     	{ on = [ "y" ],     run = "close --submit", desc = "Submit the confirm" },
    ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants