stevearc / oil.nvim

Neovim file explorer: edit your filesystem like a buffer
MIT License
3.84k stars 110 forks source link

bug: 'prompt_save_on_select_new_entry' does not use the oil prompt for confirmation #363

Open smartinellimarco opened 5 months ago

smartinellimarco commented 5 months ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

9.5.0

Operating system/version

MacOS 14.3

Describe the bug

When creating and selecting a new file, oil will prompt you to save it (as the option says), but using the commandline instead of the floating pop up.

Screenshot 2024-04-29 at 01 11 59

This prompt is shown even with 'prompt_save_on_select_new_entry' set to false.

Furthermore, pressing 'Esc' or cancelling the prompt, will open the new buffer anyways. This leads to strange behaviors, i.e, if you save the buffer before saving in oil, oil ask you to create the file afterwards anyways. I would expect oil not creating the buffer at all.

Thanks in advance!

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

  1. nvim -u repro.lua
  2. open oil
  3. create a file (don't save)
  4. select the file (open it)

Expected Behavior

Oil prompt asking for confirmation to CREATE the file before editing it.

Directory structure

foo.txt bar.txt new_file.txt

Repro

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify('./.repro', ':p')

-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'runtime', 'cache' }) do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    '--single-branch',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  'folke/tokyonight.nvim',
  {
    'stevearc/oil.nvim',
    config = function()
      require('oil').setup({
        view_options = {
          show_hidden = true,
        },
        keymaps = {
          ['l'] = 'actions.select',
          ['<CR>'] = 'actions.select',
          ['<C-v>'] = 'actions.select_vsplit',
          ['<C-x>'] = 'actions.select_split',
          ['h'] = 'actions.parent',
          ['.'] = 'actions.open_cwd',
          ['<leader>o'] = 'actions.close', -- Act as toggle
        },
        skip_confirm_for_simple_edits = true,
        prompt_save_on_select_new_entry = true,
        use_default_keymaps = false,
      })
    end,
  },
  -- add any other plugins here
}
require('lazy').setup(plugins, {
  root = root .. '/plugins',
})

vim.cmd.colorscheme('tokyonight')
-- add anything else here

Did you check the bug with a clean config?

smartinellimarco commented 3 months ago

Any ideas on how to solve this? 😢

stevearc commented 3 months ago

See #93 for context on why this option and prompt exist in the first place.

The command line prompt is because the place where I needed to inject this confirmation really was not a great location to add another callback, it would have made the code a bit too gnarly. So I used vim.fn.confirm instead because it will block execution waiting for user input. If someone wants to try to make that call async in a way that isn't horrible, be my guest. Ideally I'd like to rewrite all of oil's async logic using an async/await style library instead of using callbacks, but I've been waiting for an official Neovim implementation or at least endorsement.

https://github.com/PhilippOesch/oil.nvim/blob/7e08910104fb4d823a6d6ec8e49d14b433e8fd4b/lua/oil/init.lua#L735-L743

This prompt is shown even with 'prompt_save_on_select_new_entry' set to false.

I could not get this to repro, the option works as expected for me. Confirm that you have everything spelled correctly and that you're setting the option in the right place.

smartinellimarco commented 3 months ago

@stevearc Just to add to this issue, were you able to reproduce the double confirmation for this sequence? One from vim.fn.confirm and the other from Oil itself.