feat: Blend cursor color with cursorline
This commit is contained in:
@@ -28,6 +28,7 @@ M.defaults = {
|
||||
show_numbers = false,
|
||||
show_relative_numbers = false,
|
||||
show_cursorline = true,
|
||||
hide_cursor = false,
|
||||
winhl = "SymbolsOutlineDetails:Comment,SymbolsOutlineLineno:LineNr",
|
||||
},
|
||||
preview_window = {
|
||||
@@ -107,7 +108,7 @@ M.defaults = {
|
||||
StaticMethod = { icon = ' ', hl = '@function' },
|
||||
Macro = { icon = ' ', hl = '@macro' },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
M.o = {}
|
||||
@@ -184,6 +185,12 @@ function M.show_help()
|
||||
print(vim.inspect(M.o.keymaps))
|
||||
end
|
||||
|
||||
function M.check_config()
|
||||
if M.o.outline_window.hide_cursor and not M.o.outline_window.show_cursorline then
|
||||
vim.notify("[symbols-outline.config]: hide_cursor enabled WITHOUT cursorline enabled!", vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(options)
|
||||
vim.g.symbols_outline_loaded = 1
|
||||
M.o = vim.tbl_deep_extend('force', {}, M.defaults, options or {})
|
||||
@@ -191,6 +198,7 @@ function M.setup(options)
|
||||
if type(guides) == 'boolean' and guides then
|
||||
M.o.guides = M.defaults.guides
|
||||
end
|
||||
M.check_config()
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -46,6 +46,9 @@ M.state = {
|
||||
outline_items = {},
|
||||
flattened_outline_items = {},
|
||||
code_win = 0,
|
||||
-- In case unhide_cursor was called before hide_cursor for _some_ reason,
|
||||
-- this can still be used as a fallback
|
||||
original_cursor = vim.o.guicursor,
|
||||
}
|
||||
|
||||
local function wipe_state()
|
||||
@@ -129,6 +132,19 @@ function M._toggle_fold(move_cursor, node_index)
|
||||
end
|
||||
end
|
||||
|
||||
local function hide_cursor()
|
||||
-- Set cursor color to CursorLine in normal mode
|
||||
M.state.original_cursor = vim.o.guicursor
|
||||
local cur = vim.o.guicursor:match("n.-:(.-)[-,]")
|
||||
vim.opt.guicursor:append("n:"..cur.."-Cursorline")
|
||||
end
|
||||
|
||||
local function unhide_cursor()
|
||||
-- vim.opt doesn't seem to provide a way to remove last item, like a pop()
|
||||
-- vim.o.guicursor = vim.o.guicursor:gsub(",n.-:.-$", "")
|
||||
vim.o.guicursor = M.state.original_cursor
|
||||
end
|
||||
|
||||
local function setup_buffer_autocmd()
|
||||
if cfg.o.preview_window.auto_preview then
|
||||
vim.api.nvim_create_autocmd('CursorMoved', {
|
||||
@@ -150,6 +166,19 @@ local function setup_buffer_autocmd()
|
||||
end
|
||||
})
|
||||
end
|
||||
if cfg.o.outline_window.hide_cursor then
|
||||
-- Unfortunately guicursor is a global option, so we have to make sure to
|
||||
-- set and unset when cursor leaves the outline window.
|
||||
hide_cursor()
|
||||
vim.api.nvim_create_autocmd('BufEnter', {
|
||||
buffer = 0,
|
||||
callback = hide_cursor
|
||||
})
|
||||
vim.api.nvim_create_autocmd('BufLeave', {
|
||||
buffer = 0,
|
||||
callback = unhide_cursor
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function M._set_folded(folded, move_cursor, node_index)
|
||||
|
||||
Reference in New Issue
Block a user