@@ -101,24 +101,33 @@ function M.show_preview(
101
101
local orig_preview_width = math.floor (nvim_width * 0.4 )
102
102
local orig_preview_height = math.floor (nvim_height * 0.4 )
103
103
local preview_row , preview_col , preview_width , preview_height
104
+ local margin = main_win_config .margin
105
+ local win_row , win_col = unpack (vim .api .nvim_win_get_position (0 ))
106
+ local south_space = nvim_height - win_row - main_height - margin
107
+ local north_space = win_row - margin
104
108
105
- if main_col + main_width + 2 + orig_preview_width <= nvim_width then
109
+ if win_col + main_width + margin + orig_preview_width <= nvim_width then
106
110
preview_width = orig_preview_width
107
111
preview_height = orig_preview_height
108
112
preview_row = main_row
109
- preview_col = main_col + main_width + 2
113
+ preview_col = main_col + main_width + margin
114
+ elseif win_col > margin + orig_preview_width then
115
+ preview_width = orig_preview_width
116
+ preview_height = orig_preview_height
117
+ preview_row = main_row
118
+ preview_col = win_col - margin - orig_preview_width
119
+ elseif south_space >= north_space then
120
+ preview_width = main_width
121
+ preview_height =
122
+ math.max (0 , math.min (math.ceil (orig_preview_height / 2 ), south_space - margin ))
123
+ preview_row = win_row + main_height + margin
124
+ preview_col = main_col
110
125
else
111
- local south_space = nvim_height - (main_row + main_height ) - 2
112
- local north_space = main_row - 2
113
126
preview_width = main_width
114
- preview_height = math.ceil (orig_preview_height / 2 )
115
- if south_space >= north_space then
116
- preview_row = main_row + main_height + 2
117
- preview_col = main_col
118
- else
119
- preview_row = math.max (0 , main_row - preview_height - 2 )
120
- preview_col = main_col
121
- end
127
+ preview_height =
128
+ math.max (0 , math.min (math.ceil (orig_preview_height / 2 ), north_space - margin ))
129
+ preview_row = win_row - preview_height - margin
130
+ preview_col = main_col
122
131
end
123
132
124
133
local preview_buf = vim .api .nvim_create_buf (false , true )
0 commit comments