Refresh generated neovim config
This commit is contained in:
@ -33,4 +33,9 @@ function M.toggle(enabled)
|
||||
return Search.toggle(enabled)
|
||||
end
|
||||
|
||||
---@return string
|
||||
function M.prompt()
|
||||
return require("flash.prompt").prompt or ""
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@ -216,7 +216,7 @@ local defaults = {
|
||||
-- `require("flash").treesitter()`
|
||||
treesitter = {
|
||||
labels = "abcdefghijklmnopqrstuvwxyz",
|
||||
jump = { pos = "range" },
|
||||
jump = { pos = "range", autojump = true },
|
||||
search = { incremental = false },
|
||||
label = { before = true, after = true, style = "inline" },
|
||||
highlight = {
|
||||
@ -237,6 +237,7 @@ local defaults = {
|
||||
},
|
||||
-- options for the floating window that shows the prompt,
|
||||
-- for regular jumps
|
||||
-- `require("flash").prompt()` is always available to get the prompt text
|
||||
prompt = {
|
||||
enabled = true,
|
||||
prefix = { { "⚡", "FlashPromptIcon" } },
|
||||
@ -313,10 +314,7 @@ function M.get(...)
|
||||
o.label = vim.tbl_deep_extend("force", o.label or {}, o.highlight.label)
|
||||
---@diagnostic disable-next-line: no-unknown
|
||||
o.highlight.label = nil
|
||||
vim.notify_once(
|
||||
"flash: `opts.highlight.label` is deprecated, use `opts.label` instead",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
vim.notify_once("flash: `opts.highlight.label` is deprecated, use `opts.label` instead", vim.log.levels.WARN)
|
||||
end
|
||||
for _, field in ipairs({ "autohide", "jump_labels" }) do
|
||||
if type(o[field]) == "function" then
|
||||
|
||||
@ -124,12 +124,7 @@ function M.update(state)
|
||||
-- dont show the label if the cursor is on the same position
|
||||
-- in the same window
|
||||
-- and the label is not a range
|
||||
if
|
||||
cursor[1] == row + 1
|
||||
and cursor[2] == col
|
||||
and match.win == state.win
|
||||
and state.opts.jump.pos ~= "range"
|
||||
then
|
||||
if cursor[1] == row + 1 and cursor[2] == col and match.win == state.win and state.opts.jump.pos ~= "range" then
|
||||
return
|
||||
end
|
||||
if match.fold then
|
||||
|
||||
@ -80,10 +80,7 @@ function M.remote_op(match, state, register)
|
||||
vim.cmd("normal! v")
|
||||
vim.api.nvim_win_set_cursor(match.win, match.end_pos)
|
||||
else
|
||||
vim.api.nvim_win_set_cursor(
|
||||
match.win,
|
||||
state.opts.jump.pos == "start" and match.pos or match.end_pos
|
||||
)
|
||||
vim.api.nvim_win_set_cursor(match.win, state.opts.jump.pos == "start" and match.pos or match.end_pos)
|
||||
end
|
||||
|
||||
-- otherwise, use the remote window's cursor position
|
||||
@ -196,9 +193,7 @@ function M._jump(match, state, opts)
|
||||
offset = 1
|
||||
end
|
||||
|
||||
pos = Pos(
|
||||
require("flash.util").offset_pos(vim.api.nvim_win_get_buf(match.win), pos, { 0, offset or 0 })
|
||||
)
|
||||
pos = Pos(require("flash.util").offset_pos(vim.api.nvim_win_get_buf(match.win), pos, { 0, offset or 0 }))
|
||||
pos[2] = math.max(0, pos[2])
|
||||
|
||||
vim.api.nvim_win_set_cursor(match.win, pos)
|
||||
|
||||
@ -50,10 +50,7 @@ function M:reset()
|
||||
skip[l] = true
|
||||
end
|
||||
end
|
||||
if
|
||||
not self.state.opts.search.max_length
|
||||
or #self.state.pattern() < self.state.opts.search.max_length
|
||||
then
|
||||
if not self.state.opts.search.max_length or #self.state.pattern() < self.state.opts.search.max_length then
|
||||
for _, win in pairs(self.state.wins) do
|
||||
self.labels = self:skip(win, self.labels)
|
||||
end
|
||||
|
||||
@ -46,8 +46,7 @@ function M.new()
|
||||
}, M.motions[M.motion])
|
||||
|
||||
-- never show the current match label
|
||||
opts.highlight.groups.current = M.motion:lower() == "f" and opts.highlight.groups.label
|
||||
or opts.highlight.groups.match
|
||||
opts.highlight.groups.current = M.motion:lower() == "f" and opts.highlight.groups.label or opts.highlight.groups.match
|
||||
|
||||
-- exclude the motion labels so we can use them for next/prev
|
||||
opts.labels = opts.labels:gsub(M.motion:lower(), "")
|
||||
@ -241,7 +240,7 @@ function M.jump(key)
|
||||
M.state:update({ force = true })
|
||||
|
||||
if M.jump_labels then
|
||||
if (Config.get("char").jump.autojump and #M.state.results == 1) then
|
||||
if Config.get("char").jump.autojump and #M.state.results == 1 then
|
||||
M.state:hide()
|
||||
return M.state
|
||||
end
|
||||
|
||||
@ -9,7 +9,7 @@ local M = {}
|
||||
---@field node TSNode
|
||||
---@field depth? number
|
||||
|
||||
---@param win window
|
||||
---@param win number
|
||||
---@param pos? Pos
|
||||
function M.get_nodes(win, pos)
|
||||
local buf = vim.api.nvim_win_get_buf(win)
|
||||
@ -18,7 +18,7 @@ function M.get_nodes(win, pos)
|
||||
|
||||
local nodes = {} ---@type TSNode[]
|
||||
|
||||
local ok, tree = pcall(vim.treesitter.get_parser, buf)
|
||||
local ok, parser = pcall(vim.treesitter.get_parser, buf)
|
||||
if not ok then
|
||||
vim.notify(
|
||||
"No treesitter parser for this buffer with filetype=" .. vim.bo[buf].filetype,
|
||||
@ -27,20 +27,25 @@ function M.get_nodes(win, pos)
|
||||
)
|
||||
vim.api.nvim_input("<esc>")
|
||||
end
|
||||
if not (ok and tree) then
|
||||
if not (ok and parser) then
|
||||
return {}
|
||||
end
|
||||
|
||||
do
|
||||
-- get all ranges of the current node and its parents
|
||||
local node = tree:named_node_for_range({ pos[1] - 1, pos[2], pos[1] - 1, pos[2] }, {
|
||||
ignore_injections = false,
|
||||
})
|
||||
parser:for_each_tree(function(tstree, tree)
|
||||
if not tstree then
|
||||
return
|
||||
end
|
||||
-- get all ranges of the current node and its parents
|
||||
local node = tree:named_node_for_range({ pos[1] - 1, pos[2], pos[1] - 1, pos[2] }, {
|
||||
ignore_injections = true,
|
||||
})
|
||||
|
||||
while node do
|
||||
nodes[#nodes + 1] = node
|
||||
node = node:parent() ---@type TSNode
|
||||
end
|
||||
while node do
|
||||
nodes[#nodes + 1] = node
|
||||
node = node:parent() ---@type TSNode
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- convert ranges to matches
|
||||
@ -63,14 +68,12 @@ function M.get_nodes(win, pos)
|
||||
-- then move it to the last character of the last line.
|
||||
if match.end_pos[1] > line_count then
|
||||
match.end_pos[1] = line_count
|
||||
match.end_pos[2] =
|
||||
#vim.api.nvim_buf_get_lines(buf, match.end_pos[1] - 1, match.end_pos[1], false)[1]
|
||||
match.end_pos[2] = #vim.api.nvim_buf_get_lines(buf, match.end_pos[1] - 1, match.end_pos[1], false)[1]
|
||||
elseif match.end_pos[2] == -1 then
|
||||
-- If the end points to the start of the next line, move it to the
|
||||
-- end of the previous line.
|
||||
-- Otherwise operations include the first character of the next line
|
||||
local line =
|
||||
vim.api.nvim_buf_get_lines(buf, match.end_pos[1] - 2, match.end_pos[1] - 1, false)[1]
|
||||
local line = vim.api.nvim_buf_get_lines(buf, match.end_pos[1] - 2, match.end_pos[1] - 1, false)[1]
|
||||
match.end_pos[1] = match.end_pos[1] - 1
|
||||
match.end_pos[2] = #line
|
||||
end
|
||||
@ -121,11 +124,13 @@ function M.jump(opts)
|
||||
current = m
|
||||
end
|
||||
end
|
||||
current = state:jump(current)
|
||||
if state.opts.jump.autojump then
|
||||
current = state:jump(current)
|
||||
end
|
||||
|
||||
state:loop({
|
||||
abort = function()
|
||||
vim.cmd([[normal! v]])
|
||||
Util.exit()
|
||||
end,
|
||||
actions = {
|
||||
[";"] = function()
|
||||
@ -174,7 +179,11 @@ function M.search(opts)
|
||||
end)
|
||||
|
||||
local state = Repeat.get_state("treesitter-search", opts)
|
||||
state:loop()
|
||||
state:loop({
|
||||
abort = function()
|
||||
Util.exit()
|
||||
end,
|
||||
})
|
||||
return state
|
||||
end
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
local Config = require("flash.config")
|
||||
|
||||
---@class Flash.Prompt
|
||||
---@field win window
|
||||
---@field buf buffer
|
||||
---@field win number
|
||||
---@field buf number
|
||||
---@field prompt string
|
||||
local M = {}
|
||||
|
||||
local ns = vim.api.nvim_create_namespace("flash_prompt")
|
||||
@ -47,6 +48,8 @@ function M.show()
|
||||
end
|
||||
|
||||
function M.hide()
|
||||
M.prompt = ""
|
||||
|
||||
if M.win and vim.api.nvim_win_is_valid(M.win) then
|
||||
vim.api.nvim_win_close(M.win, true)
|
||||
M.win = nil
|
||||
@ -58,8 +61,8 @@ function M.hide()
|
||||
end
|
||||
|
||||
---@param pattern string
|
||||
function M.set(pattern)
|
||||
M.show()
|
||||
---@param show boolean
|
||||
function M.set(pattern, show)
|
||||
local text = vim.deepcopy(Config.prompt.prefix)
|
||||
text[#text + 1] = { pattern }
|
||||
|
||||
@ -67,6 +70,15 @@ function M.set(pattern)
|
||||
for _, item in ipairs(text) do
|
||||
str = str .. item[1]
|
||||
end
|
||||
|
||||
M.prompt = str
|
||||
|
||||
if not show then
|
||||
return
|
||||
end
|
||||
|
||||
M.show()
|
||||
|
||||
vim.api.nvim_buf_set_lines(M.buf, 0, -1, false, { str })
|
||||
vim.api.nvim_buf_clear_namespace(M.buf, ns, 0, -1)
|
||||
local col = 0
|
||||
|
||||
@ -56,11 +56,7 @@ function M.setup()
|
||||
local ok, err = pcall(state.update, state)
|
||||
if not ok then
|
||||
vim.schedule(function()
|
||||
vim.notify(
|
||||
"Flash error during redraw:\n" .. err,
|
||||
vim.log.levels.ERROR,
|
||||
{ title = "flash.nvim" }
|
||||
)
|
||||
vim.notify("Flash error during redraw:\n" .. err, vim.log.levels.ERROR, { title = "flash.nvim" })
|
||||
end)
|
||||
end
|
||||
end
|
||||
@ -217,9 +213,7 @@ function M:check_jump(pattern)
|
||||
return
|
||||
end
|
||||
local chars = vim.fn.strchars(pattern)
|
||||
if
|
||||
pattern:find(self.pattern(), 1, true) == 1 and chars == vim.fn.strchars(self.pattern()) + 1
|
||||
then
|
||||
if pattern:find(self.pattern(), 1, true) == 1 and chars == vim.fn.strchars(self.pattern()) + 1 then
|
||||
local label = vim.fn.strcharpart(pattern, chars - 1, 1)
|
||||
if self:jump(label) then
|
||||
return true
|
||||
@ -349,8 +343,8 @@ end
|
||||
---@param opts? Flash.Step.Options
|
||||
function M:step(opts)
|
||||
opts = opts or {}
|
||||
if self.opts.prompt.enabled and not M.is_search() then
|
||||
Prompt.set(self.pattern())
|
||||
if not M.is_search() then
|
||||
Prompt.set(self.pattern(), self.opts.prompt.enabled)
|
||||
end
|
||||
local actions = opts.actions or self.opts.actions or {}
|
||||
local c = self:get_char()
|
||||
@ -394,7 +388,7 @@ function M:step(opts)
|
||||
end
|
||||
|
||||
-- exit if no results and not in regular search mode
|
||||
if #self.results == 0 and not self.pattern:empty() and self.pattern.mode ~= 'search' then
|
||||
if #self.results == 0 and not self.pattern:empty() and self.pattern.mode ~= "search" then
|
||||
if self.opts.search.incremental then
|
||||
vim.api.nvim_input(c)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user