fix(completion): improve popup window position (#26739)

This commit is contained in:
Raphael
2024-04-25 21:36:18 +08:00
committed by GitHub
parent b13e63db1d
commit af8500af64
4 changed files with 331 additions and 207 deletions

View File

@@ -6,7 +6,9 @@
#include "klib/kvec.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/api/vim.h"
#include "nvim/ascii_defs.h"
#include "nvim/autocmd.h"
#include "nvim/buffer_defs.h"
#include "nvim/drawscreen.h"
#include "nvim/globals.h"
@@ -17,6 +19,7 @@
#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/option_defs.h"
#include "nvim/optionstr.h"
#include "nvim/pos_defs.h"
#include "nvim/strings.h"
@@ -354,3 +357,52 @@ win_T *win_float_find_altwin(const win_T *win, const tabpage_T *tp)
return (tabpage_win_valid(tp, tp->tp_prevwin) && tp->tp_prevwin != win) ? tp->tp_prevwin
: tp->tp_firstwin;
}
/// create a floating preview window.
///
/// @param[in] bool enter floating window.
/// @param[in] bool create a new buffer for window.
///
/// @return win_T
win_T *win_float_create(bool enter, bool new_buf)
{
WinConfig config = WIN_CONFIG_INIT;
config.col = curwin->w_wcol;
config.row = curwin->w_wrow;
config.relative = kFloatRelativeEditor;
config.focusable = false;
config.anchor = 0; // NW
config.noautocmd = true;
config.hide = true;
config.style = kWinStyleMinimal;
Error err = ERROR_INIT;
block_autocmds();
win_T *wp = win_new_float(NULL, false, config, &err);
if (!wp) {
unblock_autocmds();
return NULL;
}
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;
}
buf_T *buf = find_buffer_by_handle(b, &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);
}
unblock_autocmds();
wp->w_p_diff = false;
wp->w_float_is_info = true;
if (enter) {
win_enter(wp, false);
}
return wp;
}