Shougo / ddu.vim

Dark deno-powered UI framework for Vim/Neovim
MIT License
294 stars 23 forks source link

The middle of columns is displayed as the default selected item when a directory is expanded #114

Closed glassesneo closed 5 months ago

glassesneo commented 5 months ago

Problems summary

autochdirを有効にした状態で特定の手順を踏むと、ddu#start()で最初に表示される画面がカラムの途中になる

Environment Information

config

local doAction = vim.fn["ddu#ui#async_action"]

vim.fn["ddu#custom#patch_local"]("filer", {
  ui = "filer",
  uiParams = {
    filer = {
      splitDirection = "floating",
      floatingBorder = "rounded",
      previewFloating = true,
      previewFloatingBorder = "rounded",
      previewFloatingTitle = "Preview",
      previewSplit = "horizontal",
    },
  },
  sources = { "file" },
  sourceOptions = {
    file = {
      converters = {
        "converter_devicon",
      },
      columns = {
        "filename",
      },
    },
  },
})

---@param mode string|string[]
---@param key string
---@param action string
---@param args? table
local function mapAction(mode, key, action, args)
  vim.keymap.set(mode, key, function()
    if args ~= nil and next(args) then
      doAction(action, args)
    else
      doAction(action)
    end
  end, { noremap = true, silent = true, buffer = true })
end

vim.api.nvim_create_autocmd("FileType", {
  pattern = "ddu-filer",
  callback = function()
    mapAction("n", "q", "quit")
    mapAction("n", "<CR>", "itemAction", { name = "open" })
    mapAction("n", "l", "expandItem")
  end,
})

utils.map("n", "<Space><Space>", function()
  vim.fn["ddu#start"]({
    name = "filer",
    sourceOptions = {
      -- file = {
      --   path = vim.fn.expand("%:p:h"),
      -- },
    },
    uiParams = {
      filer = {
        split = "floating",
      },
    },
  })
end)

How to reproduce the problem from neovim/Vim startup (Required!)

  1. autochdirが有効な状態で、ddu#start()を上記の設定で実行
  2. 表示されているディレクトリを選択しexpandした後、そのディレクトリ内かどうかに関わらずどこでもいいのでファイルを選択しopenする
  3. openしていったんdduのuiが閉じたところで、もう一度ddu#start()を実行すると ※ 2でopenしたファイルが最初のdduの画面で下のほうにあるほど、3で最初に表示される画面が下にズレる

Screenshot (if possible)

動画内ではexpandしたディレクトリの中のファイルをopenしているが他のファイルをopenした場合でも同様に発生を確認

https://github.com/Shougo/ddu.vim/assets/61031352/0c83aaeb-0a31-43a8-b01a-c61f0e208d01

Shougo commented 5 months ago

Please don't use Lua config.

And your config is not minimal config.

Shougo commented 5 months ago

I have created the minimal vimrc. Please test it with the config.

set rtp+=~/work/ddu.vim
set rtp+=~/work/ddu-ui-ff
set rtp+=~/work/ddu-ui-filer
set rtp+=~/work/denops.vim
set rtp+=~/work/ddu-kind-file
set rtp+=~/work/ddu-column-filename
set rtp+=~/work/ddu-source-file

set autochdir

lua <<EOF
local doAction = vim.fn["ddu#ui#async_action"]

vim.fn["ddu#custom#patch_local"]("filer", {
  ui = "filer",
  uiParams = {
    filer = {
      split = "floating",
      splitDirection = "floating",
      floatingBorder = "rounded",
      previewFloating = true,
      previewFloatingBorder = "rounded",
      previewFloatingTitle = "Preview",
      previewSplit = "horizontal",
    },
  },
  sources = { "file" },
  sourceOptions = {
    file = {
      columns = {
        "filename",
      },
    },
  },
})

---@param mode string|string[]
---@param key string
---@param action string
---@param args? table
local function mapAction(mode, key, action, args)
  vim.keymap.set(mode, key, function()
    if args ~= nil and next(args) then
      doAction(action, args)
    else
      doAction(action)
    end
  end, { noremap = true, silent = true, buffer = true })
end

vim.api.nvim_create_autocmd("FileType", {
  pattern = "ddu-filer",
  callback = function()
    mapAction("n", "q", "quit")
    mapAction("n", "<CR>", "itemAction", { name = "open" })
    mapAction("n", "l", "expandItem")
  end,
})
EOF

nnoremap <Space><Space> <Cmd>call ddu#start(#{ name: 'filer' })<CR>
call ddu#start(#{ name: 'filer' })

I don't reproduce your behavior.

glassesneo commented 5 months ago

I'm terribly sorry for not getting what the minimal vimrc means. Also, thank you for your hard work.

Although I had tested ddu with your minimal vimrc, I got the same behavior. (All the plugins used in the test have already been updated to the latest version)

https://github.com/Shougo/ddu.vim/assets/61031352/f4307cdb-82ea-426d-a934-2b6611aa271e

Also, I realized that the lua config I showed first does not have columns options set in sourceOptions, but that didn't change any situations.

Shougo commented 5 months ago

Fixed. Please update ddu-ui-filer.