Skip to content

fix(#2370): Better "y/N" prompts #2377

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

Merged
merged 5 commits into from
Aug 20, 2023
Merged

fix(#2370): Better "y/N" prompts #2377

merged 5 commits into from
Aug 20, 2023

Conversation

mohamedarish
Copy link
Contributor

@mohamedarish mohamedarish commented Aug 15, 2023

fixes #2370.

Packer uses a bool flag comparing to check whether the given input is "y".

I've made it so that the default behaviour of the prompt is set to N for no (don't delete).

The default is set to R(ename) for name conflicts when copy-pasting.

Accidentally clicking enter/return after pressing d/bd should be made less common with this default behaviour.

the default behaviour is shown as a capital letter.

…te cases) and made it so that the copy paste same name conflict defaults to R(ename)
@mohamedarish mohamedarish changed the title fix(#2369): Better "y/N" prompts fix(#2370): Better "y/N" prompts Aug 15, 2023
@mohamedarish
Copy link
Contributor Author

I've thought about it and the "no" condition is unnecessary as everything that is not "y" is a no condition. I'm closing this PR and would be reopening this after I've fixed this issue.

@alex-courtis
Copy link
Member

Thanks for taking the time. This one is indeed more difficult than it appears.

@mohamedarish mohamedarish reopened this Aug 16, 2023
@mohamedarish
Copy link
Contributor Author

I've removed all "No" conditions as they are not needed as everything that is not a "y" or "yes" entered is a no condition. And would delete/replace the files

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Many thanks for your contribution. This greatly enhances UX.

  • maybe address default r
  • Please update lib.prompt to convert the callback's item_short to lowercase. Users may start using uppercase to match the prompt.

local prompt_input = prompt_select .. " y/n/r(ename): "
lib.prompt(prompt_input, prompt_select, { "y", "n", "r" }, { "Yes", "No", "Rename" }, function(item_short)
local prompt_input = prompt_select .. " R(ename)/y/n: "
lib.prompt(prompt_input, prompt_select, { "r", "y" }, { "Rename", "Yes" }, function(item_short)
Copy link
Member

Choose a reason for hiding this comment

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

This will still populate r in the prompt.

Could we do something like:

      local prompt_input = prompt_select .. " y/n/R(ename): "
      lib.prompt(prompt_input, prompt_select, { "", "y", "n" }, { "Yes", "No", "Rename", }, function(item_short)
        utils.clear_prompt()
        if item_short == "y" then
          on_process()
        elseif item_short == "" or item_short == "r" then

I might be overlooking some consideration here...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

anything that does not start with y or n shall become r in that case?
This feels wrong and having don't copy be the default case feels better

Copy link
Contributor Author

@mohamedarish mohamedarish Aug 20, 2023

Choose a reason for hiding this comment

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

I'll update the lib.prompt to make the user prompt to lowercase

Copy link
Member

Choose a reason for hiding this comment

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

anything that does not start with y or n shall become r in that case?
This feels wrong and having don't copy be the default case feels better

Yes please. Default n is consistent and arguably better behaviour. All prompts default to no.

It's a somewhat breaking change however it is quite reasonable.

Copy link
Contributor Author

@mohamedarish mohamedarish Aug 20, 2023

Choose a reason for hiding this comment

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

Currently "r" is auto filled when a name conflict on copy occurs and I feel that is a better behaviour than defaulting to don't copy in that case.
The user needs to remove the r or update the autofilled character as it provides a second chance to cancel by cancelling in the rename prompt

Copy link
Member

Choose a reason for hiding this comment

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

Currently "r" is auto filled when a name conflict on copy occurs and I feel that is a better behaviour than defaulting to don't copy in that case.

I'm happy with r as the default, however auto-filling is not consistent with other prompts. We can remove the auto-fill and rename can still be the default.

@mohamedarish
Copy link
Contributor Author

mohamedarish commented Aug 20, 2023

I've noticed that my change makes the prompt ui from dressing.nvim or telescope-ui-select.nvim
not have proper select prompts (Default(No) appears as is and does not fit into the prompt ui) and have updated the items_long to fix this and also fixed to change all item_short to be lowercase.

@alex-courtis
Copy link
Member

I've noticed that my change makes the prompt ui from dressing.nvim or telescope-ui-select.nvim not have proper select prompts (Default(No) appears as is and does not fit into the prompt ui) and have updated the items_long to fix this and also fixed to change all item_short to be lowercase.

Thank you for testing.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

Please:

  • resolve exception
  • remove auto-fill r

local prompt_input = prompt_select .. " y/n/r(ename): "
lib.prompt(prompt_input, prompt_select, { "y", "n", "r" }, { "Yes", "No", "Rename" }, function(item_short)
local prompt_input = prompt_select .. " R(ename)/y/n: "
lib.prompt(prompt_input, prompt_select, { "r", "y", "n" }, { "Rename", "Yes", "No" }, function(item_short)
Copy link
Member

Choose a reason for hiding this comment

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

On pressing escape:

E5108: Error executing lua: ...ite/pack/packer/start/mohamedarish/lua/nvim-tree/lib.lua:151: bad argument #1 to 'lower' (string expected, got nil)
stack traceback:
        [C]: in function 'lower'
        ...ite/pack/packer/start/mohamedarish/lua/nvim-tree/lib.lua:151: in function 'on_confirm'
        /usr/share/nvim/runtime/lua/vim/ui.lua:101: in function 'input'
        ...ite/pack/packer/start/mohamedarish/lua/nvim-tree/lib.lua:150: in function 'prompt'
        ...art/mohamedarish/lua/nvim-tree/actions/fs/copy-paste.lua:114: in function 'do_single_paste'
        ...art/mohamedarish/lua/nvim-tree/actions/fs/copy-paste.lua:187: in function 'f'
        ...ite/pack/packer/start/mohamedarish/lua/nvim-tree/api.lua:32: in function <...ite/pack/packer/start/mohamedarish/lua/nvim-tree/api.lua:30>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed the exception and added another condition in the elseif block for rename for rename to be "r"/"R" or ""

local prompt_input = prompt_select .. " y/n/r(ename): "
lib.prompt(prompt_input, prompt_select, { "y", "n", "r" }, { "Yes", "No", "Rename" }, function(item_short)
local prompt_input = prompt_select .. " R(ename)/y/n: "
lib.prompt(prompt_input, prompt_select, { "r", "y" }, { "Rename", "Yes" }, function(item_short)
Copy link
Member

Choose a reason for hiding this comment

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

Currently "r" is auto filled when a name conflict on copy occurs and I feel that is a better behaviour than defaulting to don't copy in that case.

I'm happy with r as the default, however auto-filling is not consistent with other prompts. We can remove the auto-fill and rename can still be the default.

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

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

All cases tested OK.

Many thanks for your contribution.

@alex-courtis alex-courtis merged commit 920868d into nvim-tree:master Aug 20, 2023
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.

Better [Y/n] Prompts
2 participants