@@ -7,20 +7,13 @@ function win.new(config)
7
7
self .config = {
8
8
width = config .width or 40 ,
9
9
max_height = config .max_height or 10 ,
10
- relative = config .relative or ' cursor' ,
11
10
cursorline = config .cursorline or false ,
12
11
wrap = config .wrap or false ,
13
12
filetype = config .filetype or ' cmp_menu' ,
14
13
winhighlight = config .winhighlight or ' Normal:NormalFloat,FloatBorder:NormalFloat' ,
15
14
padding = config .padding ,
16
15
}
17
16
18
- if self .config .relative == ' cursor' then
19
- vim .api .nvim_create_autocmd (' CursorMovedI' , {
20
- callback = function () self :update_position () end ,
21
- })
22
- end
23
-
24
17
return self
25
18
end
26
19
@@ -65,8 +58,6 @@ function win:open()
65
58
vim .api .nvim_set_option_value (' concealcursor' , ' n' , { win = self .id })
66
59
vim .api .nvim_set_option_value (' cursorlineopt' , ' line' , { win = self .id })
67
60
vim .api .nvim_set_option_value (' cursorline' , self .config .cursorline , { win = self .id })
68
-
69
- self :update_position ()
70
61
end
71
62
72
63
function win :close ()
@@ -77,7 +68,7 @@ function win:close()
77
68
end
78
69
79
70
-- todo: dynamic width
80
- function win :update_position ()
71
+ function win :update_position (relative_to )
81
72
if not self :is_open () then return end
82
73
local winnr = self :get_win ()
83
74
local config = self .config
@@ -94,7 +85,7 @@ function win:update_position()
94
85
vim .api .nvim_win_set_height (winnr , height )
95
86
96
87
-- relative to cursor
97
- if config . relative == ' cursor' then
88
+ if relative_to == ' cursor' then
98
89
local is_space_below = screen_height - cursor_row > height
99
90
100
91
if is_space_below then
@@ -104,27 +95,27 @@ function win:update_position()
104
95
end
105
96
106
97
-- relative to window
107
- elseif config . relative . id ~= nil then
108
- local relative_win_config = vim .api .nvim_win_get_config (config . relative . id )
98
+ elseif type ( relative_to ) == ' number ' then
99
+ local relative_win_config = vim .api .nvim_win_get_config (relative_to )
109
100
110
- -- todo: why is there a -5 here?
111
- local max_width_right = screen_width - cursor_col - relative_win_config .width - 5
101
+ -- todo: why is there a -7 here? probably the signcolumn stuff ?
102
+ local max_width_right = screen_width - cursor_col - relative_win_config .width - 7
112
103
local max_width_left = cursor_col
113
104
114
105
local width = math.min (math.max (max_width_left , max_width_right ), config .width )
115
106
116
107
if max_width_right >= config .width or max_width_right >= max_width_left then
117
108
vim .api .nvim_win_set_config (winnr , {
118
109
relative = ' win' ,
119
- win = config . relative . id ,
110
+ win = relative_to ,
120
111
row = 0 ,
121
112
col = relative_win_config .width ,
122
113
width = width ,
123
114
})
124
115
else
125
116
vim .api .nvim_win_set_config (winnr , {
126
117
relative = ' win' ,
127
- win = config . relative . id ,
118
+ win = relative_to ,
128
119
row = 0 ,
129
120
col = - width ,
130
121
width = width ,
0 commit comments