Skip to content

Commit

Permalink
refactor(codeaction): border margin handling + CodeActionCursorLine h…
Browse files Browse the repository at this point in the history
…ighlight (#1414)

* Remove borders

* Add code_action.cursorline opt

* Add win_margin var based on border

* Change code action cursorline hlgroup

* Add CodeActionCursorLine hlgroup link

* Remove redundant parens

* Add cursorlineopt opt
  • Loading branch information
dmun authored Mar 31, 2024
1 parent d5aa1a0 commit 4f2b81a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lua/lspsaga/codeaction/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ function act:action_callback(tuples, enriched_ctx)
:winopt({
['conceallevel'] = 2,
['concealcursor'] = 'niv',
['cursorline'] = config.code_action.cursorline,
['cursorlineopt'] = 'both',
})
:winhl('SagaNormal', 'SagaBorder')
:wininfo()
Expand All @@ -100,6 +102,7 @@ function act:action_callback(tuples, enriched_ctx)
end,
})

vim.opt.winhl:append('CursorLine:CodeActionCursorLine')
for i = 1, #content, 1 do
local row = i - 1
local col = content[i]:find('%]')
Expand Down
5 changes: 3 additions & 2 deletions lua/lspsaga/codeaction/preview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ local function create_preview_win(content, main_winid)
end

local winheight = api.nvim_win_get_height(win_conf.win)
local win_margin = config.ui.border == 'none' and 0 or 2
if win_conf.anchor:find('^S') then
opt.row = util.is_ten and win_conf.row - 3 or win_conf.row[false] - win_conf.height - 2
opt.row = util.is_ten and win_conf.row - 3 or win_conf.row[false] - win_conf.height - win_margin
max_height = util.is_ten and win_conf.row or win_conf.row[false] - win_conf.height
elseif win_conf.anchor:find('^N') then
opt.row = util.is_ten and win_conf.row + 3 or win_conf.row[false] + win_conf.height + 2
opt.row = util.is_ten and win_conf.row + 3 or win_conf.row[false] + win_conf.height + win_margin
max_height = winheight - opt.row
end

Expand Down
1 change: 1 addition & 0 deletions lua/lspsaga/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ local function hi_define()
ActionPreviewTitle = { link = 'Title' },
CodeActionText = { link = '@variable' },
CodeActionNumber = { link = 'DiffAdd' },
CodeActionCursorLine = { link = 'CursorLine' },
-- hover
HoverNormal = { link = 'SagaNormal' },
HoverBorder = { link = 'SagaBorder' },
Expand Down
1 change: 1 addition & 0 deletions lua/lspsaga/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ local default_config = {
extend_gitsigns = false,
only_in_cursor = true,
max_height = 0.3,
cursorline = true,
keys = {
quit = 'q',
exec = '<CR>',
Expand Down

0 comments on commit 4f2b81a

Please sign in to comment.