6
6
--- @field border ? blink.cmp.WindowBorder
7
7
--- @field wrap ? boolean
8
8
--- @field filetype ? string
9
+ --- @field winblend ? number
9
10
--- @field winhighlight ? string
10
11
--- @field scrolloff ? number
12
+ --- @field scrollbar ? boolean
11
13
12
14
--- @class blink.cmp.Window
13
15
--- @field id ? number
14
16
--- @field buf ? number
15
17
--- @field config blink.cmp.WindowOptions
18
+ --- @field scrollbar ? blink.cmp.Scrollbar
16
19
---
17
20
--- @field new fun ( config : blink.cmp.WindowOptions ): blink.cmp.Window
18
21
--- @field get_buf fun ( self : blink.cmp.Window ): number
@@ -52,8 +55,13 @@ function win.new(config)
52
55
winblend = config .winblend or 0 ,
53
56
winhighlight = config .winhighlight or ' Normal:NormalFloat,FloatBorder:NormalFloat' ,
54
57
scrolloff = config .scrolloff or 0 ,
58
+ scrollbar = config .scrollbar ,
55
59
}
56
60
61
+ if self .config .scrollbar then
62
+ self .scrollbar = require (' blink.cmp.windows.lib.scrollbar' ).new ({ enable_gutter = self .config .border == ' none' })
63
+ end
64
+
57
65
return self
58
66
end
59
67
@@ -100,6 +108,8 @@ function win:open()
100
108
vim .api .nvim_set_option_value (' cursorlineopt' , ' line' , { win = self .id })
101
109
vim .api .nvim_set_option_value (' cursorline' , self .config .cursorline , { win = self .id })
102
110
vim .api .nvim_set_option_value (' scrolloff' , self .config .scrolloff , { win = self .id })
111
+
112
+ if self .scrollbar then self .scrollbar :mount (self .id ) end
103
113
end
104
114
105
115
function win :set_option_value (option , value ) vim .api .nvim_set_option_value (option , value , { win = self .id }) end
@@ -109,6 +119,7 @@ function win:close()
109
119
vim .api .nvim_win_close (self .id , true )
110
120
self .id = nil
111
121
end
122
+ if self .scrollbar then self .scrollbar :unmount () end
112
123
end
113
124
114
125
--- Updates the size of the window to match the max width and height of the content/config
@@ -138,15 +149,13 @@ function win:get_content_height()
138
149
end
139
150
140
151
--- Gets the size of the borders around the window
141
- --- @param border ? ' none' | ' single' | ' double' | ' rounded' | ' solid' | ' shadow' | ' padded' | string[]
142
152
--- @return { vertical : number , horizontal : number , left : number , right : number , top : number , bottom : number }
143
- function win :get_border_size (border )
144
- if not border and not self :is_open () then
145
- return { vertical = 0 , horizontal = 0 , left = 0 , right = 0 , top = 0 , bottom = 0 }
146
- end
153
+ function win :get_border_size ()
154
+ if not self :is_open () then return { vertical = 0 , horizontal = 0 , left = 0 , right = 0 , top = 0 , bottom = 0 } end
147
155
148
- border = border or self .config .border
156
+ local border = self .config .border
149
157
if border == ' none' then
158
+ if self .config .scrollbar then return { vertical = 0 , horizontal = 1 , left = 0 , right = 1 , top = 0 , bottom = 0 } end
150
159
return { vertical = 0 , horizontal = 0 , left = 0 , right = 0 , top = 0 , bottom = 0 }
151
160
elseif border == ' padded' then
152
161
return { vertical = 0 , horizontal = 2 , left = 1 , right = 1 , top = 0 , bottom = 0 }
@@ -158,6 +167,7 @@ function win:get_border_size(border)
158
167
-- borders can be a table of strings and act differently with different # of chars
159
168
-- so we normalize it: https://neovim.io/doc/user/api.html#nvim_open_win()
160
169
-- based on nvim-cmp
170
+ -- TODO: doesn't handle scrollbar
161
171
local resolved_border = {}
162
172
while # resolved_border <= 8 do
163
173
for _ , b in ipairs (border ) do
@@ -172,6 +182,7 @@ function win:get_border_size(border)
172
182
return { vertical = top + bottom , horizontal = left + right , left = left , right = right , top = top , bottom = bottom }
173
183
end
174
184
185
+ if self .config .scrollbar then return { vertical = 0 , horizontal = 1 , left = 0 , right = 1 , top = 0 , bottom = 0 } end
175
186
return { vertical = 0 , horizontal = 0 , left = 0 , right = 0 , top = 0 , bottom = 0 }
176
187
end
177
188
0 commit comments