Skip to content

Commit 7a37c64

Browse files
authored
fix: padded window (#315)
1 parent db3d1ad commit 7a37c64

File tree

6 files changed

+61
-44
lines changed

6 files changed

+61
-44
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ MiniDeps.add({
146146
| `BlinkCmpKind` | Special | Kind icon/text of the completion item |
147147
| `BlinkCmpKind<kind>` | Special | Kind icon/text of the completion item |
148148
| `BlinkCmpDoc` | NormalFloat | The documentation window |
149-
| `BlinkCmpDocBorder` | FloatBorder | The documentation window border |
149+
| `BlinkCmpDocBorder` | NormalFloat | The documentation window border |
150150
| `BlinkCmpDocCursorLine` | Visual | The documentation window cursor line |
151151
| `BlinkCmpSignatureHelp` | NormalFloat | The signature help window |
152-
| `BlinkCmpSignatureHelpBorder` | FloatBorder | The signature help window border |
152+
| `BlinkCmpSignatureHelpBorder` | NormalFloat | The signature help window border |
153153
| `BlinkCmpSignatureHelpActiveParameter` | LspSignatureActiveParameter | Active parameter of the signature help |
154154

155155
</details>

lua/blink/cmp/init.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ cmp.add_default_highlights = function()
110110
set_hl('BlinkCmpMenuSelection', { link = 'PmenuSel' })
111111

112112
set_hl('BlinkCmpDoc', { link = 'NormalFloat' })
113-
set_hl('BlinkCmpDocBorder', { link = 'FloatBorder' })
113+
set_hl('BlinkCmpDocBorder', { link = 'NormalFloat' })
114114
set_hl('BlinkCmpDocCursorLine', { link = 'Visual' })
115115

116116
set_hl('BlinkCmpSignatureHelp', { link = 'NormalFloat' })
117-
set_hl('BlinkCmpSignatureHelpBorder', { link = 'FloatBorder' })
117+
set_hl('BlinkCmpSignatureHelpBorder', { link = 'NormalFloat' })
118118
set_hl('BlinkCmpSignatureHelpActiveParameter', { link = 'LspSignatureActiveParameter' })
119119
end
120120

lua/blink/cmp/windows/lib/init.lua

+27-19
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ function win.new(config)
5757
}
5858

5959
if self.config.scrollbar then
60-
self.scrollbar = require('blink.cmp.windows.lib.scrollbar').new({ enable_gutter = self.config.border == 'none' })
60+
self.scrollbar = require('blink.cmp.windows.lib.scrollbar').new({
61+
enable_gutter = self.config.border == 'none' or self.config.border == 'padded',
62+
})
6163
end
6264

6365
return self
@@ -149,19 +151,24 @@ end
149151
function win:get_border_size()
150152
if not self:is_open() then return { vertical = 0, horizontal = 0, left = 0, right = 0, top = 0, bottom = 0 } end
151153

154+
local left = 0
155+
local right = 0
156+
local top = 0
157+
local bottom = 0
158+
152159
local border = self.config.border
153-
if border == 'none' then
154-
if self.scrollbar and self.scrollbar:is_visible() then
155-
return { vertical = 0, horizontal = 1, left = 0, right = 1, top = 0, bottom = 0 }
156-
end
157-
return { vertical = 0, horizontal = 0, left = 0, right = 0, top = 0, bottom = 0 }
158-
elseif border == 'padded' then
159-
return { vertical = 0, horizontal = 2, left = 1, right = 1, top = 0, bottom = 0 }
160+
if border == 'padded' then
161+
left = 1
162+
right = 1
160163
elseif border == 'shadow' then
161-
return { vertical = 1, horizontal = 1, left = 0, right = 1, top = 0, bottom = 1 }
162-
elseif type(border) == 'string' then
163-
return { vertical = 2, horizontal = 2, left = 1, right = 1, top = 1, bottom = 1 }
164-
elseif type(border) == 'table' and border ~= nil then
164+
right = 1
165+
bottom = 1
166+
elseif type(border) == 'string' and border ~= 'none' then
167+
left = 1
168+
right = 1
169+
top = 1
170+
bottom = 1
171+
elseif type(border) == 'table' then
165172
-- borders can be a table of strings and act differently with different # of chars
166173
-- so we normalize it: https://neovim.io/doc/user/api.html#nvim_open_win()
167174
-- based on nvim-cmp
@@ -173,17 +180,18 @@ function win:get_border_size()
173180
end
174181
end
175182

176-
local top = resolved_border[2] == '' and 0 or 1
177-
local bottom = resolved_border[6] == '' and 0 or 1
178-
local left = resolved_border[8] == '' and 0 or 1
179-
local right = resolved_border[4] == '' and 0 or 1
180-
return { vertical = top + bottom, horizontal = left + right, left = left, right = right, top = top, bottom = bottom }
183+
top = resolved_border[2] == '' and 0 or 1
184+
bottom = resolved_border[6] == '' and 0 or 1
185+
left = resolved_border[8] == '' and 0 or 1
186+
right = resolved_border[4] == '' and 0 or 1
181187
end
182188

183189
if self.scrollbar and self.scrollbar:is_visible() then
184-
return { vertical = 0, horizontal = 1, left = 0, right = 1, top = 0, bottom = 0 }
190+
local offset = (border == 'none' or border == 'padded') and 1 or 0
191+
right = right + offset
185192
end
186-
return { vertical = 0, horizontal = 0, left = 0, right = 0, top = 0, bottom = 0 }
193+
194+
return { vertical = top + bottom, horizontal = left + right, left = left, right = right, top = top, bottom = bottom }
187195
end
188196

189197
--- Gets the height of the window, taking into account the border

lua/blink/cmp/windows/lib/scrollbar/geometry.lua

+16-9
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,34 @@ local function get_win_buf_height(target_win)
2828
return height
2929
end
3030

31+
--- @param border string|string[]
32+
--- @return number
33+
local function get_col_offset(border)
34+
-- we only need an extra offset when working with a padded window
35+
if type(border) == 'table' and border[1] == ' ' and border[4] == ' ' and border[7] == ' ' and border[8] == ' ' then
36+
return 1
37+
end
38+
return 0
39+
end
40+
3141
--- @param target_win number
3242
--- @return { should_hide: boolean, thumb: blink.cmp.ScrollbarGeometry, gutter: blink.cmp.ScrollbarGeometry }
3343
function M.get_geometry(target_win)
34-
local width = vim.api.nvim_win_get_width(target_win)
35-
local height = vim.api.nvim_win_get_height(target_win)
36-
local zindex = vim.api.nvim_win_get_config(target_win).zindex or 1
44+
local config = vim.api.nvim_win_get_config(target_win)
45+
local width = config.width
46+
local height = config.height
47+
local zindex = config.zindex
3748

3849
local buf_height = get_win_buf_height(target_win)
39-
40-
local thumb_height = math.max(1, math.floor(height * height / buf_height + 0.5) - 1)
41-
4250
local start_line = math.max(1, vim.fn.line('w0', target_win))
43-
4451
local pct = (start_line - 1) / (buf_height - height)
45-
52+
local thumb_height = math.max(1, math.floor(height * height / buf_height + 0.5) - 1)
4653
local thumb_offset = math.floor((pct * (height - thumb_height)) + 0.5)
4754

4855
local common_geometry = {
4956
width = 1,
5057
row = thumb_offset,
51-
col = width,
58+
col = width + get_col_offset(config.border),
5259
relative = 'win',
5360
win = target_win,
5461
}

lua/blink/cmp/windows/lib/scrollbar/init.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
--- @field enable_gutter boolean
33

44
--- @class blink.cmp.Scrollbar
5-
--- @field target_win? number
6-
--- @field win? blink.cmp.ScrollbarWin
5+
--- @field win blink.cmp.ScrollbarWin
76
--- @field autocmd? number
7+
--- @field target_win? number
88
---
99
--- @field new fun(opts: blink.cmp.ScrollbarConfig): blink.cmp.Scrollbar
1010
--- @field is_visible fun(self: blink.cmp.Scrollbar): boolean
@@ -56,13 +56,15 @@ function scrollbar:mount(target_win)
5656
{ 'WinScrolled', 'WinClosed', 'WinResized', 'CursorMoved', 'CursorMovedI' },
5757
{ callback = update }
5858
)
59+
self.target_win = target_win
5960
end
6061

6162
function scrollbar:unmount()
6263
self.win:hide()
6364

6465
if self.autocmd then vim.api.nvim_del_autocmd(self.autocmd) end
6566
self.autocmd = nil
67+
self.target_win = nil
6668
end
6769

6870
return scrollbar

lua/blink/cmp/windows/lib/scrollbar/win.lua

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ function scrollbar_win:show_thumb(geometry)
2525
-- create window if it doesn't exist
2626
if self.thumb_win == nil or not vim.api.nvim_win_is_valid(self.thumb_win) then
2727
self.thumb_win = self:_make_win(geometry, 'BlinkCmpScrollBarThumb')
28+
else
29+
-- update with the geometry
30+
local thumb_existing_config = vim.api.nvim_win_get_config(self.thumb_win)
31+
local thumb_config = vim.tbl_deep_extend('force', thumb_existing_config, geometry)
32+
vim.api.nvim_win_set_config(self.thumb_win, thumb_config)
2833
end
29-
30-
-- update with the geometry
31-
local thumb_existing_config = vim.api.nvim_win_get_config(self.thumb_win)
32-
local thumb_config = vim.tbl_deep_extend('force', thumb_existing_config, geometry)
33-
vim.api.nvim_win_set_config(self.thumb_win, thumb_config)
3434
end
3535

3636
function scrollbar_win:show_gutter(geometry)
@@ -39,12 +39,12 @@ function scrollbar_win:show_gutter(geometry)
3939
-- create window if it doesn't exist
4040
if self.gutter_win == nil or not vim.api.nvim_win_is_valid(self.gutter_win) then
4141
self.gutter_win = self:_make_win(geometry, 'BlinkCmpScrollBarGutter')
42+
else
43+
-- update with the geometry
44+
local gutter_existing_config = vim.api.nvim_win_get_config(self.gutter_win)
45+
local gutter_config = vim.tbl_deep_extend('force', gutter_existing_config, geometry)
46+
vim.api.nvim_win_set_config(self.gutter_win, gutter_config)
4247
end
43-
44-
-- update with the geometry
45-
local gutter_existing_config = vim.api.nvim_win_get_config(self.gutter_win)
46-
local gutter_config = vim.tbl_deep_extend('force', gutter_existing_config, geometry)
47-
vim.api.nvim_win_set_config(self.gutter_win, gutter_config)
4848
end
4949

5050
function scrollbar_win:hide_thumb()

0 commit comments

Comments
 (0)