|
29 | 29 | --- @field get_width fun(self: blink.cmp.Window): number
|
30 | 30 | --- @field get_cursor_screen_position fun(): { distance_from_top: number, distance_from_bottom: number }
|
31 | 31 | --- @field get_vertical_direction_and_height fun(self: blink.cmp.Window, direction_priority: ("n" | "s")[]): { height: number, direction: 'n' | 's' }?
|
32 |
| ---- @field get_direction_with_window_constraints fun(self: blink.cmp.Window, anchor_win: blink.cmp.Window, direction_priority: ("n" | "s" | "e" | "w")[]): { width: number, height: number, direction: 'n' | 's' | 'e' | 'w' }? |
| 32 | +--- @field get_direction_with_window_constraints fun(self: blink.cmp.Window, anchor_win: blink.cmp.Window, direction_priority: ("n" | "s" | "e" | "w")[], desired_min_size?: { width: number, height: number }): { width: number, height: number, direction: 'n' | 's' | 'e' | 'w' }? |
33 | 33 |
|
34 | 34 | --- @type blink.cmp.Window
|
35 | 35 | --- @diagnostic disable-next-line: missing-fields
|
@@ -236,7 +236,7 @@ function win:get_vertical_direction_and_height(direction_priority)
|
236 | 236 | return { height = height - border_size.vertical, direction = direction }
|
237 | 237 | end
|
238 | 238 |
|
239 |
| -function win:get_direction_with_window_constraints(anchor_win, direction_priority) |
| 239 | +function win:get_direction_with_window_constraints(anchor_win, direction_priority, desired_min_size) |
240 | 240 | local cursor_constraints = self.get_cursor_screen_position()
|
241 | 241 |
|
242 | 242 | local anchor_config = vim.fn.screenpos(anchor_win:get_win(), 1, 1)
|
@@ -289,6 +289,19 @@ function win:get_direction_with_window_constraints(anchor_win, direction_priorit
|
289 | 289 | local direction_priority_by_space = vim.fn.sort(vim.deepcopy(direction_priority), function(a, b)
|
290 | 290 | local constraints_a = direction_constraints[a]
|
291 | 291 | local constraints_b = direction_constraints[b]
|
| 292 | + |
| 293 | + local is_desired_a = desired_min_size.height <= constraints_a.vertical |
| 294 | + and desired_min_size.width <= constraints_a.horizontal |
| 295 | + local is_desired_b = desired_min_size.height <= constraints_b.vertical |
| 296 | + and desired_min_size.width <= constraints_b.horizontal |
| 297 | + |
| 298 | + -- prioritize "a" if it has the desired size |
| 299 | + if is_desired_a then return -1 end |
| 300 | + |
| 301 | + -- prioritize "b" if it has the desired size and "a" doesn't |
| 302 | + if not is_desired_a and is_desired_b then return 1 end |
| 303 | + |
| 304 | + -- neither have the desired size, so pick based on which has the most space |
292 | 305 | local distance_a = math.min(max_height, constraints_a.vertical, constraints_a.horizontal)
|
293 | 306 | local distance_b = math.min(max_height, constraints_b.vertical, constraints_b.horizontal)
|
294 | 307 | return distance_a < distance_b and 1 or distance_a > distance_b and -1 or 0
|
|
0 commit comments