aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/winfloat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/winfloat.c')
-rw-r--r--src/nvim/winfloat.c69
1 files changed, 44 insertions, 25 deletions
diff --git a/src/nvim/winfloat.c b/src/nvim/winfloat.c
index 44f0e2fc0b..8fe0315230 100644
--- a/src/nvim/winfloat.c
+++ b/src/nvim/winfloat.c
@@ -9,9 +9,9 @@
#include "nvim/ascii_defs.h"
#include "nvim/buffer_defs.h"
#include "nvim/drawscreen.h"
-#include "nvim/func_attr.h"
#include "nvim/globals.h"
#include "nvim/grid.h"
+#include "nvim/grid_defs.h"
#include "nvim/macros_defs.h"
#include "nvim/memory.h"
#include "nvim/mouse.h"
@@ -20,7 +20,9 @@
#include "nvim/optionstr.h"
#include "nvim/pos_defs.h"
#include "nvim/strings.h"
+#include "nvim/types_defs.h"
#include "nvim/ui.h"
+#include "nvim/ui_defs.h"
#include "nvim/vim_defs.h"
#include "nvim/window.h"
#include "nvim/winfloat.h"
@@ -36,7 +38,7 @@
/// @param last make the window the last one in the window list.
/// Only used when allocating the autocommand window.
/// @param config must already have been validated!
-win_T *win_new_float(win_T *wp, bool last, FloatConfig fconfig, Error *err)
+win_T *win_new_float(win_T *wp, bool last, WinConfig fconfig, Error *err)
{
if (wp == NULL) {
wp = win_alloc(last ? lastwin : lastwin_nofloating(), false);
@@ -57,7 +59,7 @@ win_T *win_new_float(win_T *wp, bool last, FloatConfig fconfig, Error *err)
int dir;
winframe_remove(wp, &dir, NULL);
XFREE_CLEAR(wp->w_frame);
- (void)win_comp_pos(); // recompute window positions
+ win_comp_pos(); // recompute window positions
win_remove(wp, NULL);
win_append(lastwin_nofloating(), wp);
}
@@ -136,7 +138,7 @@ int win_border_width(win_T *wp)
return wp->w_border_adj[1] + wp->w_border_adj[3];
}
-void win_config_float(win_T *wp, FloatConfig fconfig)
+void win_config_float(win_T *wp, WinConfig fconfig)
{
wp->w_width = MAX(fconfig.width, 1);
wp->w_height = MAX(fconfig.height, 1);
@@ -147,7 +149,9 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
fconfig.col += curwin->w_wcol;
fconfig.window = curwin->handle;
} else if (fconfig.relative == kFloatRelativeMouse) {
- int row = mouse_row, col = mouse_col, grid = mouse_grid;
+ int row = mouse_row;
+ int col = mouse_col;
+ int grid = mouse_grid;
win_T *mouse_win = mouse_find_win(&grid, &row, &col);
if (mouse_win != NULL) {
fconfig.relative = kFloatRelativeWindow;
@@ -157,17 +161,17 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
}
}
- bool change_external = fconfig.external != wp->w_float_config.external;
- bool change_border = (fconfig.border != wp->w_float_config.border
+ bool change_external = fconfig.external != wp->w_config.external;
+ bool change_border = (fconfig.border != wp->w_config.border
|| memcmp(fconfig.border_hl_ids,
- wp->w_float_config.border_hl_ids,
+ wp->w_config.border_hl_ids,
sizeof fconfig.border_hl_ids) != 0);
- wp->w_float_config = fconfig;
+ wp->w_config = fconfig;
- bool has_border = wp->w_floating && wp->w_float_config.border;
+ bool has_border = wp->w_floating && wp->w_config.border;
for (int i = 0; i < 4; i++) {
- int new_adj = has_border && wp->w_float_config.border_chars[2 * i + 1][0];
+ int new_adj = has_border && wp->w_config.border_chars[2 * i + 1][0];
if (new_adj != wp->w_border_adj[i]) {
change_border = true;
wp->w_border_adj[i] = new_adj;
@@ -180,7 +184,7 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
}
win_set_inner_size(wp, true);
- must_redraw = MAX(must_redraw, UPD_VALID);
+ set_must_redraw(UPD_VALID);
wp->w_pos_changed = true;
if (change_external || change_border) {
@@ -189,22 +193,23 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
}
// compute initial position
- if (wp->w_float_config.relative == kFloatRelativeWindow) {
- int row = (int)wp->w_float_config.row;
- int col = (int)wp->w_float_config.col;
+ if (wp->w_config.relative == kFloatRelativeWindow) {
+ int row = (int)wp->w_config.row;
+ int col = (int)wp->w_config.col;
Error dummy = ERROR_INIT;
- win_T *parent = find_window_by_handle(wp->w_float_config.window, &dummy);
+ win_T *parent = find_window_by_handle(wp->w_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;
+ int row_off = 0;
+ int col_off = 0;
grid_adjust(&grid, &row_off, &col_off);
row += row_off;
col += col_off;
- 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 };
+ if (wp->w_config.bufpos.lnum >= 0) {
+ pos_T pos = { wp->w_config.bufpos.lnum + 1,
+ wp->w_config.bufpos.col, 0 };
int trow, tcol, tcolc, tcole;
textpos2screenpos(parent, &pos, &trow, &tcol, &tcolc, &tcole, true);
row += trow - 1;
@@ -228,7 +233,9 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
static int float_zindex_cmp(const void *a, const void *b)
{
- return (*(win_T **)b)->w_float_config.zindex - (*(win_T **)a)->w_float_config.zindex;
+ int za = (*(win_T **)a)->w_config.zindex;
+ int zb = (*(win_T **)b)->w_config.zindex;
+ return za == zb ? 0 : za < zb ? 1 : -1;
}
void win_float_remove(bool bang, int count)
@@ -237,7 +244,9 @@ void win_float_remove(bool bang, int count)
for (win_T *wp = lastwin; wp && wp->w_floating; wp = wp->w_prev) {
kv_push(float_win_arr, wp);
}
- qsort(float_win_arr.items, float_win_arr.size, sizeof(win_T *), float_zindex_cmp);
+ if (float_win_arr.size > 0) {
+ qsort(float_win_arr.items, float_win_arr.size, sizeof(win_T *), float_zindex_cmp);
+ }
for (size_t i = 0; i < float_win_arr.size; i++) {
if (win_close(float_win_arr.items[i], false, false) == FAIL) {
break;
@@ -256,8 +265,8 @@ void win_check_anchored_floats(win_T *win)
{
for (win_T *wp = lastwin; wp && wp->w_floating; wp = wp->w_prev) {
// float might be anchored to moved window
- if (wp->w_float_config.relative == kFloatRelativeWindow
- && wp->w_float_config.window == win->handle) {
+ if (wp->w_config.relative == kFloatRelativeWindow
+ && wp->w_config.window == win->handle) {
wp->w_pos_changed = true;
}
}
@@ -266,7 +275,7 @@ void win_check_anchored_floats(win_T *win)
void win_reconfig_floats(void)
{
for (win_T *wp = lastwin; wp && wp->w_floating; wp = wp->w_prev) {
- win_config_float(wp, wp->w_float_config);
+ win_config_float(wp, wp->w_config);
}
}
@@ -287,3 +296,13 @@ bool win_float_valid(const win_T *win)
}
return false;
}
+
+win_T *win_float_find_preview(void)
+{
+ for (win_T *wp = lastwin; wp && wp->w_floating; wp = wp->w_prev) {
+ if (wp->w_float_is_info) {
+ return wp;
+ }
+ }
+ return NULL;
+}