goolord / alpha-nvim

a lua powered greeter like vim-startify / dashboard-nvim
MIT License
1.82k stars 109 forks source link

Issue in choosing option using 'enter' key with fzf-lua #79

Closed RayZ0rr closed 2 years ago

RayZ0rr commented 2 years ago

I am using the following config with alpha :

alpha.lua ```lua local alpha = require'alpha' local dashboard = require'alpha.themes.dashboard' dashboard.section.header.val = { [[ __ ]], [[ ___ ___ ___ __ __ /\_\ ___ ___ ]], [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]], [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]], [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], } dashboard.section.buttons.val = { dashboard.button( "e", " New file" , ":ene startinsert "), dashboard.button( "f", " > Find file", "FzfLua files"), dashboard.button( "r", " > Recent" , ":FzfLua oldfiles"), dashboard.button( "s", " > Settings" , ":e $MYVIMRC | :FzfLua files cwd=~/.config/nvim"), dashboard.button( "q", " Quit NVIM" , ":qa"), } local fortune = require("alpha.fortune") dashboard.section.footer.val = fortune() alpha.setup(dashboard.opts) -- Disable folding on alpha buffer vim.cmd([[ autocmd FileType alpha setlocal nofoldenable ]]) ```

I am not able to use the options f , r and s by pressing enter key on them. The fzf-lua opens and closes immediately. I can open these choices by pressing f , r and s keys respectively. Other choices can be selected with enter key. For s choice, selecting with enter key on it opens init.vim but not fzf-lua window. Using s key opens both.

renanbrayner commented 2 years ago

I'm having the exact same issue with junegunn/fzf, :Files, :GFiles and :History are not working.

here is the buttons section:

dashboard.section.buttons.val = {
    dashboard.button( "f", "  > Find file", ":call ControlP()<CR>"),
    dashboard.button( "r", "  > Recent"   , ":History<CR>"),
    dashboard.button( "s", "  > Settings" , ":e $MYVIMRC<CR>"),
    dashboard.button( "e", "  > New file" , ":ene<CR>"),
    dashboard.button( "q", "  > Quit NVIM", ":qa<CR>"),
}

the ControlP() function is just a function that calls :GFiles or :Files depending on if I'm inside a git project or not

goolord commented 2 years ago

this is really strange to me, the dashboard theme calls feedkeys internally when you press <CR> https://github.com/goolord/alpha-nvim/blob/main/lua/alpha/themes/dashboard.lua#L53

so pressing <CR> should result in the same behavior as you literally typing the 3rd argument to button

goolord commented 2 years ago

this problem doesn't happen with telescope or clap, i haven't used any other fuzzy finders so i don't have a great intuition for what kind of problems could arise. the two things i can think of that might be fishy off the top of my head are

  1. maybe a conflicting keybinding
  2. maybe some weird interaction with how fzf-lua creates the floating terminal window
goolord commented 2 years ago

sorry, it's pretty late and i'm not at my work machine rn so i'll continue taking notes :9 something other debugging troubleshooting steps to try dashboard.button( "s", " > Settings" , ":e $MYVIMRC | :FzfLua files cwd=~/.config/nvim | :somenoop<CR>"),

RayZ0rr commented 2 years ago

I managed to get this working for Fzf-lua by editing dashboard button function. Here's my relevant section from config. I have commented out original code above my modification for reference

local function button(sc, txt, keybind, keybind_opts)
  local sc_ = sc:gsub("%s", ""):gsub("SPC", "<leader>")

  local opts = {
    position = "center",
    shortcut = sc,
    cursor = 5,
    width = 50,
    hl = "Label",
    align_shortcut = "right",
    hl_shortcut = "Keyword",
  }
  if keybind then
    keybind_opts = if_nil(keybind_opts, { noremap = true, silent = true, nowait = true })
    -- opts.keymap = { "n", sc_, keybind, keybind_opts }
    opts.keymap = { "n", sc_, "<cmd>" .. keybind .. "<cr>", keybind_opts }
  end

  local function on_press()
    local key = vim.api.nvim_replace_termcodes(sc_ .. "<Ignore>", true, false, true)
    -- vim.api.nvim_feedkeys(key, "normal", false)
    vim.cmd(keybind)
  end

  return {
    type = "button",
    val = txt,
    on_press = on_press,
    opts = opts,
  }
end

The buttons group now looks like this:

local buttons = {
  type = "group",
  val = {
    button("e", "  New file", "ene"),
    button("f", "  File Explorer","FzfLua files"),
    button("o", "  Recently opened files","FzfLua oldfiles"),
    button("g", "  Find word","FzfLua grep_project"),
    button("m", "  Jump to bookmarks","lua require('fzf-lua').marks()"),
    button("s", "  Open last session","sessionManager load_session"),
    -- button("SPC f f", "  Find file","lua require('fzf-lua').files()"),
    -- button("SPC f o", "  Recently opened files","FzfLua oldfiles"),
    -- button("SPC f g g", "  Find word","FzfLua grep_project"),
    -- button("SPC f m", "  Jump to bookmarks","lua require('fzf-lua').marks()"),
    -- button("SPC s l", "  Open last session"),
  },
  opts = {
    spacing = 1,
  },
}

My full config is here.

goolord commented 2 years ago

ok this for sure some quirk of feedkeys. i'm going to push a hotfix that will fix this but break the button pressing queue feature

goolord commented 2 years ago

https://github.com/goolord/alpha-nvim/commit/06ade3a20ca9e79a7038b98d05a23d7b6c016174