From b3e815094bad6c28b758bc7538bf1b13936660fc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 3 Oct 2021 08:36:24 +0800 Subject: fix(float)!: always anchor to corner of window including border #15832 N, W, S, E are all inclusive, i.e., always anchor to the exact corner of the window (including border). This line may also need change in this case (change 0 to -1): This is most consistent and easiest to reason about, especially with GUIs whose border do not need to have width/height of 1/1 in cell units. Fix #15789 --- src/nvim/api/vim.c | 4 +++- src/nvim/window.c | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 3be45d0cf7..8e0502e03b 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -1360,7 +1360,9 @@ void nvim_chan_send(Integer chan, String data, Error *err) /// - `bufpos`: Places float relative to buffer text (only when /// relative="win"). Takes a tuple of zero-indexed [line, column]. /// `row` and `col` if given are applied relative to this -/// position, else they default to `row=1` and `col=0` +/// position, else they default to: +/// - `row=1` and `col=0` if `anchor` is "NW" or "NE" +/// - `row=0` and `col=0` if `anchor` is "SW" or "SE" /// (thus like a tooltip near the buffer text). /// - `row`: Row position in units of "screen cell height", may be fractional. /// - `col`: Column position in units of "screen cell width", may be diff --git a/src/nvim/window.c b/src/nvim/window.c index c0f537aab3..ff97eaa757 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -853,12 +853,12 @@ void ui_ext_win_position(win_T *wp) bool east = c.anchor & kFloatAnchorEast; bool south = c.anchor & kFloatAnchorSouth; - int comp_row = (int)row - (south ? wp->w_height : 0); - int comp_col = (int)col - (east ? wp->w_width : 0); + int comp_row = (int)row - (south ? wp->w_height_outer : 0); + int comp_col = (int)col - (east ? wp->w_width_outer : 0); comp_row += grid->comp_row; comp_col += grid->comp_col; - comp_row = MAX(MIN(comp_row, Rows-wp->w_height_outer-1), 0); - comp_col = MAX(MIN(comp_col, Columns-wp->w_width_outer), 0); + comp_row = MAX(MIN(comp_row, Rows - wp->w_height_outer - 1), 0); + comp_col = MAX(MIN(comp_col, Columns - wp->w_width_outer), 0); wp->w_winrow = comp_row; wp->w_wincol = comp_col; bool valid = (wp->w_redr_type == 0); -- cgit