Skip to content

Commit

Permalink
fix: complete path/file windows adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Feb 3, 2024
1 parent 2388156 commit 9065879
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
16 changes: 10 additions & 6 deletions lua/fzf-lua/complete.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local core = require "fzf-lua.core"
local path = require "fzf-lua.path"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"

local M = {}
Expand Down Expand Up @@ -45,7 +46,7 @@ end
-- set the cwd and prompt top the top level directory and
-- the leftover match to the input query
local set_cmp_opts_path = function(opts)
local match = "[^%s\"']*"
local match = "[^%s'" .. utils._if_win([[\/]], [[\]]) .. "]*"
local line = vim.api.nvim_get_current_line()
local col = vim.api.nvim_win_get_cursor(0)[2] + 1
local before = col > 1 and line:sub(1, col - 1):reverse():match(match):reverse() or ""
Expand All @@ -56,6 +57,7 @@ local set_cmp_opts_path = function(opts)
after = line:sub(col):match(match) or ""
end
opts._cwd, opts.cwd, opts.query = find_toplevel_cwd(before .. after, nil, nil)
print("_cwd", opts._cwd, "cwd", opts.cwd, "q", opts.query)
opts.prompt = opts._cwd
if not opts.prompt then
opts.prompt = "."
Expand Down Expand Up @@ -85,8 +87,8 @@ M.path = function(opts)
return "fdfind"
elseif vim.fn.executable("fd") == 1 then
return "fd"
elseif vim.fn.executable("rg") == 1 then
return "rg --files"
elseif utils.__IS_WINDOWS then
return "dir /s/b"
else
return [[find ! -path '.' ! -path '*/\.git/*' -printf '%P\n']]
end
Expand All @@ -101,12 +103,14 @@ M.file = function(opts)
if not opts then return end
opts.cmp_is_file = true
opts.cmd = opts.cmd or (function()
if vim.fn.executable("rg") == 1 then
return "rg --files"
elseif vim.fn.executable("fdfind") == 1 then
if vim.fn.executable("fdfind") == 1 then
return "fdfind --type f --exclude .git"
elseif vim.fn.executable("fd") == 1 then
return "fd --type f --exclude .git"
elseif vim.fn.executable("rg") == 1 then
return "rg --files"
elseif utils.__IS_WINDOWS then
return "dir /s/b"
else
return [[find -type f ! -path '*/\.git/*' -printf '%P\n']]
end
Expand Down
13 changes: 7 additions & 6 deletions lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,13 @@ M.defaults.dap = {
}

M.defaults.complete_path = {
cmd = nil, -- default: auto detect fd|rg|find
file_icons = false,
git_icons = false,
color_icons = true,
fzf_opts = { ["--no-multi"] = true },
actions = { ["default"] = actions.complete },
cmd = nil, -- default: auto detect fd|rg|find
file_icons = false,
git_icons = false,
color_icons = true,
multiprocess = true,
fzf_opts = { ["--no-multi"] = true },
actions = { ["default"] = actions.complete },
}

M.defaults.complete_file = {
Expand Down
2 changes: 1 addition & 1 deletion lua/fzf-lua/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
-- This "retires" 'actions.ensure_insert_mode' and solves the
-- issue of calling an fzf-lua mapping from insert mode (#429)

if vim.fn.has("nvim-0.6") == 1 then
if vim.fn.has("nvim-0.6") == 1 and vim.api.nvim_get_mode().mode ~= "i" then
vim.cmd([[noautocmd lua vim.api.nvim_feedkeys(]]
.. [[vim.api.nvim_replace_termcodes("<Esc>i", true, false, true)]]
.. [[, 'n', true)]])
Expand Down

0 comments on commit 9065879

Please sign in to comment.