fix: floating window highlights (#149)
This commit is contained in:
parent
9211babf09
commit
8c8d864637
@ -640,11 +640,11 @@ end
|
|||||||
function M.choose(side)
|
function M.choose(side)
|
||||||
local bufnr = api.nvim_get_current_buf()
|
local bufnr = api.nvim_get_current_buf()
|
||||||
if vim.fn.mode() == "v" or vim.fn.mode() == "V" or vim.fn.mode() == "" then
|
if vim.fn.mode() == "v" or vim.fn.mode() == "V" or vim.fn.mode() == "" then
|
||||||
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
|
api.nvim_feedkeys(api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
|
||||||
-- have to defer so that the < and > marks are set
|
-- have to defer so that the < and > marks are set
|
||||||
vim.defer_fn(function()
|
vim.defer_fn(function()
|
||||||
local start = vim.api.nvim_buf_get_mark(0, "<")[1]
|
local start = api.nvim_buf_get_mark(0, "<")[1]
|
||||||
local finish = vim.api.nvim_buf_get_mark(0, ">")[1]
|
local finish = api.nvim_buf_get_mark(0, ">")[1]
|
||||||
local position = find_position(bufnr, function(line, pos)
|
local position = find_position(bufnr, function(line, pos)
|
||||||
local left = pos.current.range_start >= start - 1
|
local left = pos.current.range_start >= start - 1
|
||||||
local right = pos.incoming.range_end <= finish + 1
|
local right = pos.incoming.range_end <= finish + 1
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
local api = vim.api
|
||||||
|
|
||||||
|
local namespace = api.nvim_create_namespace("avante_floating_window")
|
||||||
|
|
||||||
|
api.nvim_set_hl(namespace, "NormalFloat", { link = "Normal" })
|
||||||
|
api.nvim_set_hl(namespace, "FloatBorder", { link = "Normal" })
|
||||||
|
|
||||||
---@class FloatingWindow
|
---@class FloatingWindow
|
||||||
---@field enter boolean | nil
|
---@field enter boolean | nil
|
||||||
---@field winid integer | nil
|
---@field winid integer | nil
|
||||||
@ -35,28 +42,30 @@ end
|
|||||||
|
|
||||||
---@return nil
|
---@return nil
|
||||||
function FloatingWindow:mount()
|
function FloatingWindow:mount()
|
||||||
self.bufnr = vim.api.nvim_create_buf(false, true)
|
self.bufnr = api.nvim_create_buf(false, true)
|
||||||
|
|
||||||
for option, value in pairs(self.buf_options) do
|
for option, value in pairs(self.buf_options) do
|
||||||
vim.api.nvim_set_option_value(option, value, { buf = self.bufnr })
|
api.nvim_set_option_value(option, value, { buf = self.bufnr })
|
||||||
end
|
end
|
||||||
|
|
||||||
self.winid = vim.api.nvim_open_win(self.bufnr, self.enter, self.float_options)
|
self.winid = api.nvim_open_win(self.bufnr, self.enter, self.float_options)
|
||||||
|
|
||||||
for option, value in pairs(self.win_options) do
|
for option, value in pairs(self.win_options) do
|
||||||
vim.api.nvim_set_option_value(option, value, { win = self.winid })
|
api.nvim_set_option_value(option, value, { win = self.winid })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
api.nvim_win_set_hl_ns(self.winid, namespace)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return nil
|
---@return nil
|
||||||
function FloatingWindow:unmount()
|
function FloatingWindow:unmount()
|
||||||
if self.bufnr and vim.api.nvim_buf_is_valid(self.bufnr) then
|
if self.bufnr and api.nvim_buf_is_valid(self.bufnr) then
|
||||||
vim.api.nvim_buf_delete(self.bufnr, { force = true })
|
api.nvim_buf_delete(self.bufnr, { force = true })
|
||||||
self.bufnr = nil
|
self.bufnr = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.winid and vim.api.nvim_win_is_valid(self.winid) then
|
if self.winid and api.nvim_win_is_valid(self.winid) then
|
||||||
vim.api.nvim_win_close(self.winid, true)
|
api.nvim_win_close(self.winid, true)
|
||||||
self.winid = nil
|
self.winid = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -66,7 +75,7 @@ end
|
|||||||
---@param options? table<"'once'" | "'nested'", boolean>
|
---@param options? table<"'once'" | "'nested'", boolean>
|
||||||
---@return nil
|
---@return nil
|
||||||
function FloatingWindow:on(event, handler, options)
|
function FloatingWindow:on(event, handler, options)
|
||||||
vim.api.nvim_create_autocmd(event, {
|
api.nvim_create_autocmd(event, {
|
||||||
buffer = self.bufnr,
|
buffer = self.bufnr,
|
||||||
callback = handler,
|
callback = handler,
|
||||||
once = options and options["once"] or false,
|
once = options and options["once"] or false,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
local api = vim.api
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
TITLE = "AvanteTitle",
|
TITLE = "AvanteTitle",
|
||||||
REVERSED_TITLE = "AvanteReversedTitle",
|
REVERSED_TITLE = "AvanteReversedTitle",
|
||||||
@ -9,14 +11,14 @@ local M = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
M.setup = function()
|
M.setup = function()
|
||||||
local normal = vim.api.nvim_get_hl(0, { name = "Normal" })
|
local normal = api.nvim_get_hl(0, { name = "Normal" })
|
||||||
vim.api.nvim_set_hl(0, M.REVERSED_NORMAL, { fg = normal.bg })
|
api.nvim_set_hl(0, M.REVERSED_NORMAL, { fg = normal.bg })
|
||||||
vim.api.nvim_set_hl(0, M.TITLE, { fg = "#1e222a", bg = "#98c379" })
|
api.nvim_set_hl(0, M.TITLE, { fg = "#1e222a", bg = "#98c379" })
|
||||||
vim.api.nvim_set_hl(0, M.REVERSED_TITLE, { fg = "#98c379" })
|
api.nvim_set_hl(0, M.REVERSED_TITLE, { fg = "#98c379" })
|
||||||
vim.api.nvim_set_hl(0, M.SUBTITLE, { fg = "#1e222a", bg = "#56b6c2" })
|
api.nvim_set_hl(0, M.SUBTITLE, { fg = "#1e222a", bg = "#56b6c2" })
|
||||||
vim.api.nvim_set_hl(0, M.REVERSED_SUBTITLE, { fg = "#56b6c2" })
|
api.nvim_set_hl(0, M.REVERSED_SUBTITLE, { fg = "#56b6c2" })
|
||||||
vim.api.nvim_set_hl(0, M.THRIDTITLE, { fg = "#ABB2BF", bg = "#353B45" })
|
api.nvim_set_hl(0, M.THRIDTITLE, { fg = "#ABB2BF", bg = "#353B45" })
|
||||||
vim.api.nvim_set_hl(0, M.REVERSED_THRIDTITLE, { fg = "#353B45" })
|
api.nvim_set_hl(0, M.REVERSED_THRIDTITLE, { fg = "#353B45" })
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@ -63,7 +63,7 @@ Replace lines: {{start_line}}-{{end_line}}
|
|||||||
Remember: Accurate line numbers are CRITICAL. The range start_line to end_line must include ALL lines to be replaced, from the very first to the very last. Double-check every range before finalizing your response, paying special attention to the start_line to ensure it hasn't shifted down. Ensure that your line numbers perfectly match the original code structure without any overall shift.
|
Remember: Accurate line numbers are CRITICAL. The range start_line to end_line must include ALL lines to be replaced, from the very first to the very last. Double-check every range before finalizing your response, paying special attention to the start_line to ensure it hasn't shifted down. Ensure that your line numbers perfectly match the original code structure without any overall shift.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local group = vim.api.nvim_create_augroup("AvanteLLM", { clear = true })
|
local group = api.nvim_create_augroup("AvanteLLM", { clear = true })
|
||||||
local active_job = nil
|
local active_job = nil
|
||||||
|
|
||||||
---@param question string
|
---@param question string
|
||||||
|
@ -11,7 +11,7 @@ local Selection = {}
|
|||||||
|
|
||||||
Selection.did_setup = false
|
Selection.did_setup = false
|
||||||
|
|
||||||
---@param id integer the tabpage id retrieved from vim.api.nvim_get_current_tabpage()
|
---@param id integer the tabpage id retrieved from api.nvim_get_current_tabpage()
|
||||||
function Selection:new(id)
|
function Selection:new(id)
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
hints_popup_extmark_id = nil,
|
hints_popup_extmark_id = nil,
|
||||||
@ -46,7 +46,7 @@ function Selection:show_hints_popup()
|
|||||||
|
|
||||||
local virt_text_line = self:get_virt_text_line()
|
local virt_text_line = self:get_virt_text_line()
|
||||||
|
|
||||||
self.hints_popup_extmark_id = vim.api.nvim_buf_set_extmark(0, NAMESPACE, virt_text_line, -1, {
|
self.hints_popup_extmark_id = api.nvim_buf_set_extmark(0, NAMESPACE, virt_text_line, -1, {
|
||||||
virt_text = { { hint_text, "Keyword" } },
|
virt_text = { { hint_text, "Keyword" } },
|
||||||
virt_text_pos = "eol",
|
virt_text_pos = "eol",
|
||||||
priority = PRIORITY,
|
priority = PRIORITY,
|
||||||
@ -55,7 +55,7 @@ end
|
|||||||
|
|
||||||
function Selection:close_hints_popup()
|
function Selection:close_hints_popup()
|
||||||
if self.hints_popup_extmark_id then
|
if self.hints_popup_extmark_id then
|
||||||
vim.api.nvim_buf_del_extmark(0, NAMESPACE, self.hints_popup_extmark_id)
|
api.nvim_buf_del_extmark(0, NAMESPACE, self.hints_popup_extmark_id)
|
||||||
self.hints_popup_extmark_id = nil
|
self.hints_popup_extmark_id = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -93,7 +93,7 @@ end
|
|||||||
|
|
||||||
function Selection:delete_autocmds()
|
function Selection:delete_autocmds()
|
||||||
if self.augroup then
|
if self.augroup then
|
||||||
vim.api.nvim_del_augroup_by_id(self.augroup)
|
api.nvim_del_augroup_by_id(self.augroup)
|
||||||
end
|
end
|
||||||
self.augroup = nil
|
self.augroup = nil
|
||||||
Selection.did_setup = false
|
Selection.did_setup = false
|
||||||
|
@ -38,7 +38,7 @@ local Sidebar = {}
|
|||||||
---@field input_container NuiSplit | nil
|
---@field input_container NuiSplit | nil
|
||||||
---@field input NuiSplit | nil
|
---@field input NuiSplit | nil
|
||||||
|
|
||||||
---@param id integer the tabpage id retrieved from vim.api.nvim_get_current_tabpage()
|
---@param id integer the tabpage id retrieved from api.nvim_get_current_tabpage()
|
||||||
function Sidebar:new(id)
|
function Sidebar:new(id)
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
id = id,
|
id = id,
|
||||||
@ -65,7 +65,7 @@ end
|
|||||||
|
|
||||||
function Sidebar:delete_autocmds()
|
function Sidebar:delete_autocmds()
|
||||||
if self.augroup then
|
if self.augroup then
|
||||||
vim.api.nvim_del_augroup_by_id(self.augroup)
|
api.nvim_del_augroup_by_id(self.augroup)
|
||||||
end
|
end
|
||||||
self.augroup = nil
|
self.augroup = nil
|
||||||
end
|
end
|
||||||
@ -603,7 +603,7 @@ function Sidebar:on_mount()
|
|||||||
api.nvim_create_autocmd("WinLeave", {
|
api.nvim_create_autocmd("WinLeave", {
|
||||||
group = self.augroup,
|
group = self.augroup,
|
||||||
callback = function()
|
callback = function()
|
||||||
previous_winid = vim.api.nvim_get_current_win()
|
previous_winid = api.nvim_get_current_win()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -1141,8 +1141,8 @@ function Sidebar:get_selected_code_size()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function create_floating_window_for_split(split_winid, buf_opts, win_opts, float_opts)
|
local function create_floating_window_for_split(split_winid, buf_opts, win_opts, float_opts)
|
||||||
local height = vim.api.nvim_win_get_height(split_winid)
|
local height = api.nvim_win_get_height(split_winid)
|
||||||
local width = vim.api.nvim_win_get_width(split_winid)
|
local width = api.nvim_win_get_width(split_winid)
|
||||||
|
|
||||||
local float_opts_ = vim.tbl_deep_extend("force", {
|
local float_opts_ = vim.tbl_deep_extend("force", {
|
||||||
relative = "win",
|
relative = "win",
|
||||||
@ -1182,7 +1182,6 @@ function Sidebar:render()
|
|||||||
buf_options = buf_options,
|
buf_options = buf_options,
|
||||||
win_options = get_win_options(),
|
win_options = get_win_options(),
|
||||||
size = {
|
size = {
|
||||||
height = math.max(0, sidebar_height - selected_code_size - 8),
|
|
||||||
width = string.format("%d%%", Config.windows.width),
|
width = string.format("%d%%", Config.windows.width),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -159,7 +159,7 @@ function M.notify(msg, opts)
|
|||||||
vim.wo[win].conceallevel = 3
|
vim.wo[win].conceallevel = 3
|
||||||
vim.wo[win].concealcursor = ""
|
vim.wo[win].concealcursor = ""
|
||||||
vim.wo[win].spell = false
|
vim.wo[win].spell = false
|
||||||
local buf = vim.api.nvim_win_get_buf(win)
|
local buf = api.nvim_win_get_buf(win)
|
||||||
if not pcall(vim.treesitter.start, buf, lang) then
|
if not pcall(vim.treesitter.start, buf, lang) then
|
||||||
vim.bo[buf].filetype = lang
|
vim.bo[buf].filetype = lang
|
||||||
vim.bo[buf].syntax = lang
|
vim.bo[buf].syntax = lang
|
||||||
|
Loading…
x
Reference in New Issue
Block a user