diff options
Diffstat (limited to 'src/nvim/winfloat.c')
-rw-r--r-- | src/nvim/winfloat.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/nvim/winfloat.c b/src/nvim/winfloat.c index e3ca0ff139..fdb65ad614 100644 --- a/src/nvim/winfloat.c +++ b/src/nvim/winfloat.c @@ -10,12 +10,15 @@ #include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer_defs.h" +#include "nvim/decoration.h" #include "nvim/drawscreen.h" +#include "nvim/errors.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/message.h" #include "nvim/mouse.h" #include "nvim/move.h" #include "nvim/option.h" @@ -56,7 +59,7 @@ win_T *win_new_float(win_T *wp, bool last, WinConfig fconfig, Error *err) if (!tp) { return NULL; } - tp_last = tp->tp_lastwin; + tp_last = tp == curtab ? lastwin : tp->tp_lastwin; while (tp_last->w_floating && tp_last->w_prev) { tp_last = tp_last->w_prev; } @@ -200,7 +203,7 @@ void win_config_float(win_T *wp, WinConfig fconfig) wp->w_config.border_hl_ids, sizeof fconfig.border_hl_ids) != 0); - wp->w_config = fconfig; + merge_win_config(&wp->w_config, fconfig); bool has_border = wp->w_floating && wp->w_config.border; for (int i = 0; i < 4; i++) { @@ -358,6 +361,21 @@ win_T *win_float_find_altwin(const win_T *win, const tabpage_T *tp) : tp->tp_firstwin; } +/// Inline helper function for handling errors and cleanup in win_float_create. +static inline win_T *handle_error_and_cleanup(win_T *wp, Error *err) +{ + if (ERROR_SET(err)) { + emsg(err->msg); + api_clear_error(err); + } + if (wp) { + win_remove(wp, NULL); + win_free(wp, NULL); + } + unblock_autocmds(); + return NULL; +} + /// create a floating preview window. /// /// @param[in] bool enter floating window. @@ -380,23 +398,25 @@ win_T *win_float_create(bool enter, bool new_buf) block_autocmds(); win_T *wp = win_new_float(NULL, false, config, &err); if (!wp) { - unblock_autocmds(); - return NULL; + return handle_error_and_cleanup(wp, &err); } if (new_buf) { Buffer b = nvim_create_buf(false, true, &err); if (!b) { - win_remove(wp, NULL); - win_free(wp, NULL); - unblock_autocmds(); - return NULL; + return handle_error_and_cleanup(wp, &err); } buf_T *buf = find_buffer_by_handle(b, &err); + if (!buf) { + return handle_error_and_cleanup(wp, &err); + } buf->b_p_bl = false; // unlist set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("wipe"), OPT_LOCAL, 0, kOptReqBuf, buf); win_set_buf(wp, buf, &err); + if (ERROR_SET(&err)) { + return handle_error_and_cleanup(wp, &err); + } } unblock_autocmds(); wp->w_p_diff = false; |