Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
17766:be00d5dad3f5 | 17767:c75da1064e33 |
---|---|
636 static int | 636 static int |
637 pum_set_selected(int n, int repeat) | 637 pum_set_selected(int n, int repeat) |
638 { | 638 { |
639 int resized = FALSE; | 639 int resized = FALSE; |
640 int context = pum_height / 2; | 640 int context = pum_height / 2; |
641 #ifdef FEAT_TEXT_PROP | |
642 int has_info = FALSE; | |
643 #endif | |
641 | 644 |
642 pum_selected = n; | 645 pum_selected = n; |
643 | 646 |
644 if (pum_selected >= 0 && pum_selected < pum_size) | 647 if (pum_selected >= 0 && pum_selected < pum_size) |
645 { | 648 { |
688 { | 691 { |
689 /* scroll up */ | 692 /* scroll up */ |
690 pum_first = pum_selected + context - pum_height + 1; | 693 pum_first = pum_selected + context - pum_height + 1; |
691 } | 694 } |
692 } | 695 } |
696 // adjust for the number of lines displayed | |
697 if (pum_first > pum_size - pum_height) | |
698 pum_first = pum_size - pum_height; | |
693 | 699 |
694 #if defined(FEAT_QUICKFIX) | 700 #if defined(FEAT_QUICKFIX) |
695 /* | 701 /* |
696 * Show extra info in the preview window if there is something and | 702 * Show extra info in the preview window if there is something and |
697 * 'completeopt' contains "preview". | 703 * 'completeopt' contains "preview" or "popup". |
698 * Skip this when tried twice already. | 704 * Skip this when tried twice already. |
699 * Skip this also when there is not much room. | 705 * Skip this also when there is not much room. |
700 * NOTE: Be very careful not to sync undo! | 706 * NOTE: Be very careful not to sync undo! |
701 */ | 707 */ |
702 if (pum_array[pum_selected].pum_info != NULL | 708 if (pum_array[pum_selected].pum_info != NULL |
705 && vim_strchr(p_cot, 'p') != NULL) | 711 && vim_strchr(p_cot, 'p') != NULL) |
706 { | 712 { |
707 win_T *curwin_save = curwin; | 713 win_T *curwin_save = curwin; |
708 tabpage_T *curtab_save = curtab; | 714 tabpage_T *curtab_save = curtab; |
709 int res = OK; | 715 int res = OK; |
710 | 716 # ifdef FEAT_TEXT_PROP |
711 /* Open a preview window. 3 lines by default. Prefer | 717 int use_popup = strstr((char *)p_cot, "popup") != NULL; |
712 * 'previewheight' if set and smaller. */ | 718 # else |
719 # define use_popup 0 | |
720 # endif | |
721 has_info = TRUE; | |
722 | |
723 // Open a preview window. 3 lines by default. Prefer | |
724 // 'previewheight' if set and smaller. | |
713 g_do_tagpreview = 3; | 725 g_do_tagpreview = 3; |
714 if (p_pvh > 0 && p_pvh < g_do_tagpreview) | 726 if (p_pvh > 0 && p_pvh < g_do_tagpreview) |
715 g_do_tagpreview = p_pvh; | 727 g_do_tagpreview = p_pvh; |
716 ++RedrawingDisabled; | 728 ++RedrawingDisabled; |
717 /* Prevent undo sync here, if an autocommand syncs undo weird | 729 // Prevent undo sync here, if an autocommand syncs undo weird |
718 * things can happen to the undo tree. */ | 730 // things can happen to the undo tree. |
719 ++no_u_sync; | 731 ++no_u_sync; |
720 resized = prepare_tagpreview(FALSE); | 732 resized = prepare_tagpreview(FALSE, FALSE, use_popup); |
721 --no_u_sync; | 733 --no_u_sync; |
722 --RedrawingDisabled; | 734 --RedrawingDisabled; |
723 g_do_tagpreview = 0; | 735 g_do_tagpreview = 0; |
724 | 736 |
725 if (curwin->w_p_pvw) | 737 if (curwin->w_p_pvw |
726 { | 738 # ifdef FEAT_TEXT_PROP |
739 || (curwin->w_popup_flags & POPF_INFO) | |
740 # endif | |
741 ) | |
742 { | |
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 | |
727 if (!resized | 761 if (!resized |
728 && curbuf->b_nwindows == 1 | 762 && curbuf->b_nwindows == 1 |
729 && curbuf->b_fname == NULL | 763 && curbuf->b_fname == NULL |
730 && bt_nofile(curbuf) | 764 && bt_nofile(curbuf) |
731 && curbuf->b_p_bh[0] == 'w') | 765 && curbuf->b_p_bh[0] == 'w') |
732 { | 766 { |
733 /* Already a "wipeout" buffer, make it empty. */ | 767 // Already a "wipeout" buffer, make it empty. |
734 while (!BUFEMPTY()) | 768 while (!BUFEMPTY()) |
735 ml_delete((linenr_T)1, FALSE); | 769 ml_delete((linenr_T)1, FALSE); |
736 } | 770 } |
737 else | 771 else |
738 { | 772 { |
739 /* Don't want to sync undo in the current buffer. */ | 773 // Don't want to sync undo in the current buffer. |
740 ++no_u_sync; | 774 ++no_u_sync; |
741 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); | 775 res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL); |
742 --no_u_sync; | 776 --no_u_sync; |
743 if (res == OK) | 777 if (res == OK) |
744 { | 778 { |
745 /* Edit a new, empty buffer. Set options for a "wipeout" | 779 // Edit a new, empty buffer. Set options for a "wipeout" |
746 * buffer. */ | 780 // buffer. |
747 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); | 781 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL); |
748 set_option_value((char_u *)"bt", 0L, | 782 set_option_value((char_u *)"bt", 0L, |
749 (char_u *)"nofile", OPT_LOCAL); | 783 (char_u *)"nofile", OPT_LOCAL); |
750 set_option_value((char_u *)"bh", 0L, | 784 set_option_value((char_u *)"bh", 0L, |
751 (char_u *)"wipe", OPT_LOCAL); | 785 (char_u *)"wipe", OPT_LOCAL); |
772 ml_append(lnum++, p, (int)(e - p + 1), FALSE); | 806 ml_append(lnum++, p, (int)(e - p + 1), FALSE); |
773 *e = '\n'; | 807 *e = '\n'; |
774 p = e + 1; | 808 p = e + 1; |
775 } | 809 } |
776 } | 810 } |
811 // delete the empty last line | |
812 ml_delete(curbuf->b_ml.ml_line_count, FALSE); | |
777 | 813 |
778 /* Increase the height of the preview window to show the | 814 /* Increase the height of the preview window to show the |
779 * text, but no more than 'previewheight' lines. */ | 815 * text, but no more than 'previewheight' lines. */ |
780 if (repeat == 0) | 816 if (repeat == 0 && !use_popup) |
781 { | 817 { |
782 if (lnum > p_pvh) | 818 if (lnum > p_pvh) |
783 lnum = p_pvh; | 819 lnum = p_pvh; |
784 if (curwin->w_height < lnum) | 820 if (curwin->w_height < lnum) |
785 { | 821 { |
790 | 826 |
791 curbuf->b_changed = 0; | 827 curbuf->b_changed = 0; |
792 curbuf->b_p_ma = FALSE; | 828 curbuf->b_p_ma = FALSE; |
793 curwin->w_cursor.lnum = 1; | 829 curwin->w_cursor.lnum = 1; |
794 curwin->w_cursor.col = 0; | 830 curwin->w_cursor.col = 0; |
831 if (use_popup && win_valid(curwin_save)) | |
832 redraw_win_later(curwin_save, SOME_VALID); | |
795 | 833 |
796 if ((curwin != curwin_save && win_valid(curwin_save)) | 834 if ((curwin != curwin_save && win_valid(curwin_save)) |
797 || (curtab != curtab_save | 835 || (curtab != curtab_save |
798 && valid_tabpage(curtab_save))) | 836 && valid_tabpage(curtab_save))) |
799 { | 837 { |
850 win_enter(firstwin, TRUE); | 888 win_enter(firstwin, TRUE); |
851 # endif | 889 # endif |
852 } | 890 } |
853 #endif | 891 #endif |
854 } | 892 } |
893 # ifdef FEAT_TEXT_PROP | |
894 if (!has_info) | |
895 // close any popup info window | |
896 popup_close_preview(TRUE); | |
897 # endif | |
855 | 898 |
856 if (!resized) | 899 if (!resized) |
857 pum_redraw(); | 900 pum_redraw(); |
858 | 901 |
859 return resized; | 902 return resized; |
867 { | 910 { |
868 pum_array = NULL; | 911 pum_array = NULL; |
869 redraw_all_later(NOT_VALID); | 912 redraw_all_later(NOT_VALID); |
870 redraw_tabline = TRUE; | 913 redraw_tabline = TRUE; |
871 status_redraw_all(); | 914 status_redraw_all(); |
915 #ifdef FEAT_TEXT_PROP | |
916 // close any popup info window | |
917 popup_close_preview(TRUE); | |
918 #endif | |
872 } | 919 } |
873 | 920 |
874 /* | 921 /* |
875 * Clear the popup menu. Currently only resets the offset to the first | 922 * Clear the popup menu. Currently only resets the offset to the first |
876 * displayed item. | 923 * displayed item. |