diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-09-12 09:23:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-12 09:23:47 +0200 |
commit | cd4ec810e9f60024518405f50991d34a2c5af325 (patch) | |
tree | 908712871887192e619bad44cd42b202d774fb7c | |
parent | e2c3bcd52cb64a0138c31b610c29c55ca54b3f6a (diff) | |
parent | 9065730680d1a52f7487ff555bdb1f5b11904c88 (diff) | |
download | rneovim-cd4ec810e9f60024518405f50991d34a2c5af325.tar.gz rneovim-cd4ec810e9f60024518405f50991d34a2c5af325.tar.bz2 rneovim-cd4ec810e9f60024518405f50991d34a2c5af325.zip |
Merge pull request #14770 from andrew-pa/fix13403
Fix relative float positioning
-rw-r--r-- | src/nvim/window.c | 34 | ||||
-rw-r--r-- | test/functional/ui/float_spec.lua | 126 |
2 files changed, 159 insertions, 1 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index 42fe2c0f49..55a7882401 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -737,6 +737,37 @@ void win_config_float(win_T *wp, FloatConfig fconfig) redraw_later(wp, NOT_VALID); } + // compute initial position + if (wp->w_float_config.relative == kFloatRelativeWindow) { + int row = wp->w_float_config.row; + int col = wp->w_float_config.col; + Error dummy = ERROR_INIT; + win_T *parent = find_window_by_handle(wp->w_float_config.window, &dummy); + if (parent) { + row += parent->w_winrow; + col += parent->w_wincol; + ScreenGrid *grid = &parent->w_grid; + int row_off = 0, col_off = 0; + screen_adjust_grid(&grid, &row_off, &col_off); + row += row_off; + col += col_off; + } + api_clear_error(&dummy); + if (wp->w_float_config.bufpos.lnum >= 0) { + pos_T pos = { wp->w_float_config.bufpos.lnum + 1, + wp->w_float_config.bufpos.col, 0 }; + int trow, tcol, tcolc, tcole; + textpos2screenpos(wp, &pos, &trow, &tcol, &tcolc, &tcole, true); + row += trow - 1; + col += tcol - 1; + } + wp->w_winrow = row; + wp->w_wincol = col; + } else { + wp->w_winrow = fconfig.row; + wp->w_wincol = fconfig.col; + } + // changing border style while keeping border only requires redrawing border if (fconfig.border) { wp->w_redr_border = true; @@ -770,7 +801,6 @@ int win_fdccol_count(win_T *wp) } } - void ui_ext_win_position(win_T *wp) { if (!wp->w_floating) { @@ -817,6 +847,8 @@ void ui_ext_win_position(win_T *wp) int comp_row = (int)row - (south ? wp->w_height : 0); int comp_col = (int)col - (east ? wp->w_width : 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); wp->w_winrow = comp_row; diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index ad97af9535..ccf5f963d1 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -153,6 +153,132 @@ describe('float window', function() eq(10, width) end) + it('opened with correct position', function() + local pos = exec_lua([[ + local bufnr = vim.api.nvim_create_buf(false, true) + + local opts = { + width = 10, + height = 10, + col = 7, + row = 9, + relative = 'editor', + style = 'minimal' + } + + local win_id = vim.api.nvim_open_win(bufnr, false, opts) + + return vim.api.nvim_win_get_position(win_id) + ]]) + + eq(9, pos[1]) + eq(7, pos[2]) + end) + + it('opened with correct position relative to the cursor', function() + local pos = exec_lua([[ + local bufnr = vim.api.nvim_create_buf(false, true) + + local opts = { + width = 10, + height = 10, + col = 7, + row = 9, + relative = 'cursor', + style = 'minimal' + } + + local win_id = vim.api.nvim_open_win(bufnr, false, opts) + + return vim.api.nvim_win_get_position(win_id) + ]]) + + eq(9, pos[1]) + eq(7, pos[2]) + end) + + it('opened with correct position relative to another window', function() + local pos = exec_lua([[ + local bufnr = vim.api.nvim_create_buf(false, true) + + local par_opts = { + width = 50, + height = 50, + col = 7, + row = 9, + relative = 'editor', + style = 'minimal' + } + + local par_win_id = vim.api.nvim_open_win(bufnr, false, par_opts) + + local opts = { + width = 10, + height = 10, + col = 7, + row = 9, + relative = 'win', + style = 'minimal', + win = par_win_id + } + + local win_id = vim.api.nvim_open_win(bufnr, false, opts) + + return vim.api.nvim_win_get_position(win_id) + ]]) + + eq(18, pos[1]) + eq(14, pos[2]) + end) + + + it('opened with correct position relative to another relative window', function() + local pos = exec_lua([[ + local bufnr = vim.api.nvim_create_buf(false, true) + + local root_opts = { + width = 50, + height = 50, + col = 7, + row = 9, + relative = 'editor', + style = 'minimal' + } + + local root_win_id = vim.api.nvim_open_win(bufnr, false, root_opts) + + local par_opts = { + width = 20, + height = 20, + col = 2, + row = 3, + relative = 'win', + win = root_win_id, + style = 'minimal' + } + + local par_win_id = vim.api.nvim_open_win(bufnr, false, par_opts) + + local opts = { + width = 10, + height = 10, + col = 3, + row = 2, + relative = 'win', + win = par_win_id, + style = 'minimal' + } + + local win_id = vim.api.nvim_open_win(bufnr, false, opts) + + return vim.api.nvim_win_get_position(win_id) + ]]) + + eq(14, pos[1]) + eq(12, pos[2]) + end) + + local function with_ext_multigrid(multigrid) local screen before_each(function() |