fix rename
This commit is contained in:
1 parent
570d3a5476
commit
b3ecdea33b
1 file changed
+62
-28
@@ -34,7 +34,8 @@ local function editor_width(prompt, default)
|
||||
local columns = vim.o.columns
|
||||
local minimum = math.max(20, math.floor(columns * 0.2))
|
||||
local maximum = math.min(140, math.floor(columns * 0.9), columns - 4)
|
||||
local preferred = math.max(
|
||||
local preferred =
|
||||
math.max(
|
||||
40,
|
||||
vim.api.nvim_strwidth(prompt) + 4,
|
||||
vim.api.nvim_strwidth(default) + 2
|
||||
@@ -46,7 +47,8 @@ end
|
||||
|
||||
local function cursor_width(prompt, default)
|
||||
local maximum = math.min(80, vim.o.columns - 2)
|
||||
local preferred = math.max(
|
||||
local preferred =
|
||||
math.max(
|
||||
32,
|
||||
vim.api.nvim_strwidth(title(prompt)),
|
||||
vim.api.nvim_strwidth(default) + 2
|
||||
@@ -58,7 +60,8 @@ local function window_config(opts, prompt, default)
|
||||
if opts.scope == "cursor" or opts.scope == "line" then
|
||||
local width = cursor_width(prompt, default)
|
||||
local position = vim.fn.screenpos(0, vim.fn.line("."), vim.fn.col("."))
|
||||
local screen_column = math.max(0, (position.curscol or position.col or 1) - 1)
|
||||
local screen_column =
|
||||
math.max(0, (position.curscol or position.col or 1) - 1)
|
||||
local column = 0
|
||||
if screen_column + width + 2 > vim.o.columns then
|
||||
column = vim.o.columns - screen_column - width - 2
|
||||
@@ -156,7 +159,10 @@ local function show_next()
|
||||
local position = window_config(opts, prompt, default)
|
||||
local bufnr = vim.api.nvim_create_buf(false, true)
|
||||
local mode = vim.api.nvim_get_mode().mode:sub(1, 1)
|
||||
local winid = vim.api.nvim_open_win(
|
||||
local origin_winid = vim.api.nvim_get_current_win()
|
||||
local origin_cursor = vim.api.nvim_win_get_cursor(origin_winid)
|
||||
local winid =
|
||||
vim.api.nvim_open_win(
|
||||
bufnr,
|
||||
true,
|
||||
{
|
||||
@@ -179,6 +185,8 @@ local function show_next()
|
||||
history_tip = nil,
|
||||
mode = mode,
|
||||
opts = opts,
|
||||
origin_cursor = origin_cursor,
|
||||
origin_winid = origin_winid,
|
||||
winid = winid
|
||||
}
|
||||
|
||||
@@ -213,30 +221,41 @@ local function show_next()
|
||||
if opts.completion then
|
||||
vim.bo[bufnr].completefunc = "v:lua.require'darcula.ui.input'.completefunc"
|
||||
if not has_cmp or not pcall(require, "cmp_omni") then
|
||||
vim.keymap.set("i", "<Tab>", M.trigger_completion, {
|
||||
buffer = bufnr,
|
||||
expr = true,
|
||||
silent = true
|
||||
})
|
||||
vim.keymap.set(
|
||||
"i",
|
||||
"<Tab>",
|
||||
M.trigger_completion,
|
||||
{
|
||||
buffer = bufnr,
|
||||
expr = true,
|
||||
silent = true
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd({"TextChanged", "TextChangedI"}, {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
keep_one_line()
|
||||
apply_highlight()
|
||||
end
|
||||
})
|
||||
vim.api.nvim_create_autocmd("BufLeave", {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
if context and context.bufnr == bufnr and not context.closing then
|
||||
M.cancel()
|
||||
vim.api.nvim_create_autocmd(
|
||||
{"TextChanged", "TextChangedI"},
|
||||
{
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
keep_one_line()
|
||||
apply_highlight()
|
||||
end
|
||||
end,
|
||||
once = true
|
||||
})
|
||||
}
|
||||
)
|
||||
vim.api.nvim_create_autocmd(
|
||||
"BufLeave",
|
||||
{
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
if context and context.bufnr == bufnr and not context.closing then
|
||||
M.cancel()
|
||||
end
|
||||
end,
|
||||
once = true
|
||||
}
|
||||
)
|
||||
|
||||
apply_highlight()
|
||||
vim.cmd("startinsert!")
|
||||
@@ -264,10 +283,25 @@ local function finish(value)
|
||||
vim.cmd("stopinsert")
|
||||
end
|
||||
|
||||
vim.schedule(function()
|
||||
vim.schedule(show_next)
|
||||
finished.callback(value)
|
||||
end)
|
||||
vim.schedule(
|
||||
function()
|
||||
-- Leaving insert mode moves the cursor one column left in the original
|
||||
-- window. Restore it so callbacks (e.g. LSP rename) see the original
|
||||
-- position.
|
||||
if
|
||||
finished.mode ~= "i" and
|
||||
vim.api.nvim_win_is_valid(finished.origin_winid)
|
||||
then
|
||||
pcall(
|
||||
vim.api.nvim_win_set_cursor,
|
||||
finished.origin_winid,
|
||||
finished.origin_cursor
|
||||
)
|
||||
end
|
||||
vim.schedule(show_next)
|
||||
finished.callback(value)
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
function M.confirm()
|
||||
|
||||
Reference in new issue
Block a user