@@ -638,6 +638,9 @@ pum_set_selected(int n, int repeat)
638638{
639639 int resized = FALSE;
640640 int context = pum_height / 2 ;
641+ #ifdef FEAT_TEXT_PROP
642+ int has_info = FALSE;
643+ #endif
641644
642645 pum_selected = n ;
643646
@@ -690,11 +693,14 @@ pum_set_selected(int n, int repeat)
690693 pum_first = pum_selected + context - pum_height + 1 ;
691694 }
692695 }
696+ // adjust for the number of lines displayed
697+ if (pum_first > pum_size - pum_height )
698+ pum_first = pum_size - pum_height ;
693699
694700#if defined(FEAT_QUICKFIX )
695701 /*
696702 * Show extra info in the preview window if there is something and
697- * 'completeopt' contains "preview".
703+ * 'completeopt' contains "preview" or "popup" .
698704 * Skip this when tried twice already.
699705 * Skip this also when there is not much room.
700706 * NOTE: Be very careful not to sync undo!
@@ -707,43 +713,71 @@ pum_set_selected(int n, int repeat)
707713 win_T * curwin_save = curwin ;
708714 tabpage_T * curtab_save = curtab ;
709715 int res = OK ;
716+ # ifdef FEAT_TEXT_PROP
717+ int use_popup = strstr ((char * )p_cot , "popup" ) != NULL ;
718+ # else
719+ # define use_popup 0
720+ # endif
721+ has_info = TRUE;
710722
711- /* Open a preview window. 3 lines by default. Prefer
712- * 'previewheight' if set and smaller. */
723+ // Open a preview window. 3 lines by default. Prefer
724+ // 'previewheight' if set and smaller.
713725 g_do_tagpreview = 3 ;
714726 if (p_pvh > 0 && p_pvh < g_do_tagpreview )
715727 g_do_tagpreview = p_pvh ;
716728 ++ RedrawingDisabled ;
717- /* Prevent undo sync here, if an autocommand syncs undo weird
718- * things can happen to the undo tree. */
729+ // Prevent undo sync here, if an autocommand syncs undo weird
730+ // things can happen to the undo tree.
719731 ++ no_u_sync ;
720- resized = prepare_tagpreview (FALSE);
732+ resized = prepare_tagpreview (FALSE, FALSE, use_popup );
721733 -- no_u_sync ;
722734 -- RedrawingDisabled ;
723735 g_do_tagpreview = 0 ;
724736
725- if (curwin -> w_p_pvw )
737+ if (curwin -> w_p_pvw
738+ # ifdef FEAT_TEXT_PROP
739+ || (curwin -> w_popup_flags & POPF_INFO )
740+ # endif
741+ )
726742 {
743+ # ifdef FEAT_TEXT_PROP
744+ if (use_popup )
745+ {
746+ int col = pum_col + pum_width + 1 ;
747+
748+ if (Columns - col < 20 && Columns - col < pum_col )
749+ {
750+ col = pum_col - 1 ;
751+ curwin -> w_popup_pos = POPPOS_TOPRIGHT ;
752+ curwin -> w_maxwidth = pum_col - 1 ;
753+ }
754+ else
755+ curwin -> w_maxwidth = Columns - col + 1 ;
756+ curwin -> w_maxwidth -= popup_extra_width (curwin );
757+ popup_set_wantpos_rowcol (curwin ,
758+ pum_row + pum_selected - pum_first , col );
759+ }
760+ # endif
727761 if (!resized
728762 && curbuf -> b_nwindows == 1
729763 && curbuf -> b_fname == NULL
730764 && bt_nofile (curbuf )
731765 && curbuf -> b_p_bh [0 ] == 'w' )
732766 {
733- /* Already a "wipeout" buffer, make it empty. */
767+ // Already a "wipeout" buffer, make it empty.
734768 while (!BUFEMPTY ())
735769 ml_delete ((linenr_T )1 , FALSE);
736770 }
737771 else
738772 {
739- /* Don't want to sync undo in the current buffer. */
773+ // Don't want to sync undo in the current buffer.
740774 ++ no_u_sync ;
741775 res = do_ecmd (0 , NULL , NULL , NULL , ECMD_ONE , 0 , NULL );
742776 -- no_u_sync ;
743777 if (res == OK )
744778 {
745- /* Edit a new, empty buffer. Set options for a "wipeout"
746- * buffer. */
779+ // Edit a new, empty buffer. Set options for a "wipeout"
780+ // buffer.
747781 set_option_value ((char_u * )"swf" , 0L , NULL , OPT_LOCAL );
748782 set_option_value ((char_u * )"bt" , 0L ,
749783 (char_u * )"nofile" , OPT_LOCAL );
@@ -774,10 +808,12 @@ pum_set_selected(int n, int repeat)
774808 p = e + 1 ;
775809 }
776810 }
811+ // delete the empty last line
812+ ml_delete (curbuf -> b_ml .ml_line_count , FALSE);
777813
778814 /* Increase the height of the preview window to show the
779815 * text, but no more than 'previewheight' lines. */
780- if (repeat == 0 )
816+ if (repeat == 0 && ! use_popup )
781817 {
782818 if (lnum > p_pvh )
783819 lnum = p_pvh ;
@@ -792,6 +828,8 @@ pum_set_selected(int n, int repeat)
792828 curbuf -> b_p_ma = FALSE;
793829 curwin -> w_cursor .lnum = 1 ;
794830 curwin -> w_cursor .col = 0 ;
831+ if (use_popup && win_valid (curwin_save ))
832+ redraw_win_later (curwin_save , SOME_VALID );
795833
796834 if ((curwin != curwin_save && win_valid (curwin_save ))
797835 || (curtab != curtab_save
@@ -852,6 +890,11 @@ pum_set_selected(int n, int repeat)
852890 }
853891#endif
854892 }
893+ # ifdef FEAT_TEXT_PROP
894+ if (!has_info )
895+ // close any popup info window
896+ popup_close_preview (TRUE);
897+ # endif
855898
856899 if (!resized )
857900 pum_redraw ();
@@ -869,6 +912,10 @@ pum_undisplay(void)
869912 redraw_all_later (NOT_VALID );
870913 redraw_tabline = TRUE;
871914 status_redraw_all ();
915+ #ifdef FEAT_TEXT_PROP
916+ // close any popup info window
917+ popup_close_preview (TRUE);
918+ #endif
872919}
873920
874921/*
0 commit comments