mirror of
https://github.com/neovim/neovim.git
synced 2026-08-30 11:02:01 +00:00
fix(completion): set 'wrap' and scrolloff=0 in preview window (#37327)
Problem: info/preview floating windows are created without wrap enabled, causing info text to be truncated. Solution: enable 'wrap' and set 'scrolloff' to 0 by default, like vim's popup_create does.
This commit is contained in:
@@ -1010,7 +1010,7 @@ win_T *pum_set_info(int selected, char *info)
|
|||||||
no_u_sync++;
|
no_u_sync++;
|
||||||
win_T *wp = win_float_find_preview();
|
win_T *wp = win_float_find_preview();
|
||||||
if (wp == NULL) {
|
if (wp == NULL) {
|
||||||
wp = win_float_create(false, true);
|
wp = win_float_create_preview(false, true);
|
||||||
if (!wp) {
|
if (!wp) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1138,7 +1138,7 @@ static bool pum_set_selected(int n, int repeat)
|
|||||||
if (wp) {
|
if (wp) {
|
||||||
win_enter(wp, false);
|
win_enter(wp, false);
|
||||||
} else {
|
} else {
|
||||||
wp = win_float_create(true, true);
|
wp = win_float_create_preview(true, true);
|
||||||
if (wp) {
|
if (wp) {
|
||||||
resized = true;
|
resized = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ win_T *win_float_find_altwin(const win_T *win, const tabpage_T *tp)
|
|||||||
return (wp->w_config.focusable && !wp->w_config.hide) ? wp : tp->tp_firstwin;
|
return (wp->w_config.focusable && !wp->w_config.hide) ? wp : tp->tp_firstwin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Inline helper function for handling errors and cleanup in win_float_create.
|
/// Inline helper function for handling errors and cleanup in win_float_create_preview.
|
||||||
static inline win_T *handle_error_and_cleanup(win_T *wp, Error *err)
|
static inline win_T *handle_error_and_cleanup(win_T *wp, Error *err)
|
||||||
{
|
{
|
||||||
if (ERROR_SET(err)) {
|
if (ERROR_SET(err)) {
|
||||||
@@ -424,7 +424,7 @@ static inline win_T *handle_error_and_cleanup(win_T *wp, Error *err)
|
|||||||
/// @param[in] bool create a new buffer for window.
|
/// @param[in] bool create a new buffer for window.
|
||||||
///
|
///
|
||||||
/// @return win_T
|
/// @return win_T
|
||||||
win_T *win_float_create(bool enter, bool new_buf)
|
win_T *win_float_create_preview(bool enter, bool new_buf)
|
||||||
{
|
{
|
||||||
WinConfig config = WIN_CONFIG_INIT;
|
WinConfig config = WIN_CONFIG_INIT;
|
||||||
config.col = curwin->w_wcol;
|
config.col = curwin->w_wcol;
|
||||||
@@ -464,6 +464,8 @@ win_T *win_float_create(bool enter, bool new_buf)
|
|||||||
unblock_autocmds();
|
unblock_autocmds();
|
||||||
wp->w_p_diff = false;
|
wp->w_p_diff = false;
|
||||||
wp->w_float_is_info = true;
|
wp->w_float_is_info = true;
|
||||||
|
wp->w_p_wrap = true; // 'wrap' is default on
|
||||||
|
wp->w_p_so = 0; // 'scrolloff' zero
|
||||||
if (enter) {
|
if (enter) {
|
||||||
win_enter(wp, false);
|
win_enter(wp, false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2274,6 +2274,18 @@ describe('builtin popupmenu', function()
|
|||||||
local info = fn.complete_info()
|
local info = fn.complete_info()
|
||||||
eq(true, api.nvim_win_get_config(info.preview_winid).hide)
|
eq(true, api.nvim_win_get_config(info.preview_winid).hide)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('enables wrap to avoid info text truncation', function()
|
||||||
|
screen:try_resize(50, 11)
|
||||||
|
command([[
|
||||||
|
set nowrap
|
||||||
|
set cot+=menuone
|
||||||
|
let g:list = [#{word: 'class', info: repeat('+', 60)}]
|
||||||
|
]])
|
||||||
|
feed('S<C-x><C-o>')
|
||||||
|
local info = fn.complete_info()
|
||||||
|
eq(2, api.nvim_win_get_config(info.preview_winid).height)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('with vsplits', function()
|
it('with vsplits', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user