Mercurial > vim
diff src/popupmnu.c @ 17767:c75da1064e33 v8.1.1880
patch 8.1.1880: cannot show extra info for completion in a popup window
commit https://github.com/vim/vim/commit/576a4a6ff14da876d7c4418e5f27e926fcfa8d2a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 18 15:25:17 2019 +0200
patch 8.1.1880: cannot show extra info for completion in a popup window
Problem: Cannot show extra info for completion in a popup window.
Solution: Add the "popup" entry in 'completeopt'.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 18 Aug 2019 15:30:06 +0200 |
parents | 431d52b7f7d3 |
children | b423bd231f33 |
line wrap: on
line diff
--- a/src/popupmnu.c +++ b/src/popupmnu.c @@ -638,6 +638,9 @@ pum_set_selected(int n, int repeat) { int resized = FALSE; int context = pum_height / 2; +#ifdef FEAT_TEXT_PROP + int has_info = FALSE; +#endif pum_selected = n; @@ -690,11 +693,14 @@ pum_set_selected(int n, int repeat) pum_first = pum_selected + context - pum_height + 1; } } + // adjust for the number of lines displayed + if (pum_first > pum_size - pum_height) + pum_first = pum_size - pum_height; #if defined(FEAT_QUICKFIX) /* * Show extra info in the preview window if there is something and - * 'completeopt' contains "preview". + * 'completeopt' contains "preview" or "popup". * Skip this when tried twice already. * Skip this also when there is not much room. * NOTE: Be very careful not to sync undo! @@ -707,43 +713,71 @@ pum_set_selected(int n, int repeat) win_T *curwin_save = curwin; tabpage_T *curtab_save = curtab; int res = OK; +# ifdef FEAT_TEXT_PROP + int use_popup = strstr((char *)p_cot, "popup") != NULL; +# else +# define use_popup 0 +# endif + has_info = TRUE; - /* Open a preview window. 3 lines by default. Prefer - * 'previewheight' if set and smaller. */ + // Open a preview window. 3 lines by default. Prefer + // 'previewheight' if set and smaller. g_do_tagpreview = 3; if (p_pvh > 0 && p_pvh < g_do_tagpreview) g_do_tagpreview = p_pvh; ++RedrawingDisabled; - /* Prevent undo sync here, if an autocommand syncs undo weird - * things can happen to the undo tree. */ + // Prevent undo sync here, if an autocommand syncs undo weird + // things can happen to the undo tree. ++no_u_sync; - resized = prepare_tagpreview(FALSE); + resized = prepare_tagpreview(FALSE, FALSE, use_popup); --no_u_sync; --RedrawingDisabled; g_do_tagpreview = 0; - if (curwin->w_p_pvw) + if (curwin->w_p_pvw +# ifdef FEAT_TEXT_PROP + || (curwin->w_popup_flags & POPF_INFO) +# endif + ) { +# ifdef FEAT_TEXT_PROP + if (use_popup) + { + int col = pum_col + pum_width + 1; + + if (Columns - col < 20 && Columns - col < pum_col) + { + col = pum_col - 1; + curwin->w_popup_pos = POPPOS_TOPRIGHT; + curwin->w_maxwidth = pum_col - 1; + } + else + curwin->w_maxwidth = Columns - col + 1; + curwin->w_maxwidth -= popup_extra_width(curwin); + popup_set_wantpos_rowcol(curwin, + pum_row + pum_selected - pum_first, col); + } +# endif if (!resized && curbuf->b_nwindows == 1 && curbuf->b_fname == NULL && bt_nofile(curbuf) && curbuf->b_p_bh[0] == 'w') { - /* Already a "wipeout" buffer, make it empty. */ + // Already a "wipeout" buffer, make it empty. while (!BUFEMPTY()) ml_delete((linenr_T)1, FALSE); } else { - /* Don't want to sync undo in the current buffer. */ + // Don't want to sync undo in the current buffer. ++no_u_sync; res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); --no_u_sync; if (res == OK) { - /* Edit a new, empty buffer. Set options for a "wipeout" - * buffer. */ + // Edit a new, empty buffer. Set options for a "wipeout" + // buffer. set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); @@ -774,10 +808,12 @@ pum_set_selected(int n, int repeat) p = e + 1; } } + // delete the empty last line + ml_delete(curbuf->b_ml.ml_line_count, FALSE); /* Increase the height of the preview window to show the * text, but no more than 'previewheight' lines. */ - if (repeat == 0) + if (repeat == 0 && !use_popup) { if (lnum > p_pvh) lnum = p_pvh; @@ -792,6 +828,8 @@ pum_set_selected(int n, int repeat) curbuf->b_p_ma = FALSE; curwin->w_cursor.lnum = 1; curwin->w_cursor.col = 0; + if (use_popup && win_valid(curwin_save)) + redraw_win_later(curwin_save, SOME_VALID); if ((curwin != curwin_save && win_valid(curwin_save)) || (curtab != curtab_save @@ -852,6 +890,11 @@ pum_set_selected(int n, int repeat) } #endif } +# ifdef FEAT_TEXT_PROP + if (!has_info) + // close any popup info window + popup_close_preview(TRUE); +# endif if (!resized) pum_redraw(); @@ -869,6 +912,10 @@ pum_undisplay(void) redraw_all_later(NOT_VALID); redraw_tabline = TRUE; status_redraw_all(); +#ifdef FEAT_TEXT_PROP + // close any popup info window + popup_close_preview(TRUE); +#endif } /*