]> granicus.if.org Git - vim/commitdiff
patch 8.2.4655: cmdline completion popup menu positioned wrong v8.2.4655
authorYegappan Lakshmanan <yegappan@yahoo.com>
Thu, 31 Mar 2022 11:34:15 +0000 (12:34 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 31 Mar 2022 11:34:15 +0000 (12:34 +0100)
Problem:    Command line completion popup menu positioned wrong when using a
            terminal window.
Solution:   Position the popup menu differently when editing the command line.
            (Yegappan Lakshmanan, closes #10050, closes #10035)

src/popupmenu.c
src/testdir/dumps/Test_wildmenu_pum_term_01.dump [new file with mode: 0644]
src/testdir/test_cmdline.vim
src/testdir/test_terminal.vim
src/version.c

index 18f24803358bfdff1774f8c6ddf4bf7367cd293b..f05b7bd94d2f21630a1a7c4858aa22c9e4c05eb4 100644 (file)
@@ -100,6 +100,9 @@ pum_display(
 #if defined(FEAT_QUICKFIX)
     win_T      *pvwin;
 #endif
+#ifdef FEAT_RIGHTLEFT
+    int                right_left = State == CMDLINE ? FALSE : curwin->w_p_rl;
+#endif
 
     do
     {
@@ -156,11 +159,17 @@ pum_display(
        {
            // pum above "pum_win_row"
 
-           // Leave two lines of context if possible
-           if (curwin->w_wrow - curwin->w_cline_row >= 2)
-               context_lines = 2;
+           if (State == CMDLINE)
+               // for cmdline pum, no need for context lines
+               context_lines = 0;
            else
-               context_lines = curwin->w_wrow - curwin->w_cline_row;
+           {
+               // Leave two lines of context if possible
+               if (curwin->w_wrow - curwin->w_cline_row >= 2)
+                   context_lines = 2;
+               else
+                   context_lines = curwin->w_wrow - curwin->w_cline_row;
+           }
 
            if (pum_win_row >= size + context_lines)
            {
@@ -182,14 +191,20 @@ pum_display(
        {
            // pum below "pum_win_row"
 
-           // Leave two lines of context if possible
-           validate_cheight();
-           if (curwin->w_cline_row
-                               + curwin->w_cline_height - curwin->w_wrow >= 3)
-               context_lines = 3;
+           if (State == CMDLINE)
+               // for cmdline pum, no need for context lines
+               context_lines = 0;
            else
-               context_lines = curwin->w_cline_row
-                                   + curwin->w_cline_height - curwin->w_wrow;
+           {
+               // Leave two lines of context if possible
+               validate_cheight();
+               if (curwin->w_cline_row
+                               + curwin->w_cline_height - curwin->w_wrow >= 3)
+                   context_lines = 3;
+               else
+                   context_lines = curwin->w_cline_row
+                                    + curwin->w_cline_height - curwin->w_wrow;
+           }
 
            pum_row = pum_win_row + context_lines;
            if (size > below_row - pum_row)
@@ -226,7 +241,7 @@ pum_display(
        else
 #endif
 #ifdef FEAT_RIGHTLEFT
-       if (curwin->w_p_rl)
+       if (right_left)
            cursor_col = curwin->w_wincol + curwin->w_width
                                                          - curwin->w_wcol - 1;
        else
@@ -245,12 +260,10 @@ pum_display(
        if (def_width < max_width)
            def_width = max_width;
 
-       if (((cursor_col < Columns - p_pw
-                                          || cursor_col < Columns - max_width)
+       if (((cursor_col < Columns - p_pw || cursor_col < Columns - max_width)
 #ifdef FEAT_RIGHTLEFT
-                   && !curwin->w_p_rl)
-              || (curwin->w_p_rl
-                              && (cursor_col > p_pw || cursor_col > max_width)
+                   && !right_left)
+              || (right_left && (cursor_col > p_pw || cursor_col > max_width)
 #endif
           ))
        {
@@ -259,7 +272,7 @@ pum_display(
 
            // start with the maximum space available
 #ifdef FEAT_RIGHTLEFT
-           if (curwin->w_p_rl)
+           if (right_left)
                pum_width = pum_col - pum_scrollbar + 1;
            else
 #endif
@@ -276,22 +289,22 @@ pum_display(
            }
            else if (((cursor_col > p_pw || cursor_col > max_width)
 #ifdef FEAT_RIGHTLEFT
-                       && !curwin->w_p_rl)
-               || (curwin->w_p_rl && (cursor_col < Columns - p_pw
+                       && !right_left)
+               || (right_left && (cursor_col < Columns - p_pw
                        || cursor_col < Columns - max_width)
 #endif
                    ))
            {
                // align pum edge with "cursor_col"
 #ifdef FEAT_RIGHTLEFT
-               if (curwin->w_p_rl
+               if (right_left
                        && W_ENDCOL(curwin) < max_width + pum_scrollbar + 1)
                {
                    pum_col = cursor_col + max_width + pum_scrollbar + 1;
                    if (pum_col >= Columns)
                        pum_col = Columns - 1;
                }
-               else if (!curwin->w_p_rl)
+               else if (!right_left)
 #endif
                {
                    if (curwin->w_wincol > Columns - max_width - pum_scrollbar
@@ -305,7 +318,7 @@ pum_display(
                }
 
 #ifdef FEAT_RIGHTLEFT
-               if (curwin->w_p_rl)
+               if (right_left)
                    pum_width = pum_col - pum_scrollbar + 1;
                else
 #endif
@@ -315,7 +328,7 @@ pum_display(
                {
                    pum_width = p_pw;
 #ifdef FEAT_RIGHTLEFT
-                   if (curwin->w_p_rl)
+                   if (right_left)
                    {
                        if (pum_width > pum_col)
                            pum_width = pum_col;
@@ -343,7 +356,7 @@ pum_display(
        {
            // not enough room, will use what we have
 #ifdef FEAT_RIGHTLEFT
-           if (curwin->w_p_rl)
+           if (right_left)
                pum_col = Columns - 1;
            else
 #endif
@@ -355,7 +368,7 @@ pum_display(
            if (max_width > p_pw)
                max_width = p_pw;       // truncate
 #ifdef FEAT_RIGHTLEFT
-           if (curwin->w_p_rl)
+           if (right_left)
                pum_col = max_width - 1;
            else
 #endif
diff --git a/src/testdir/dumps/Test_wildmenu_pum_term_01.dump b/src/testdir/dumps/Test_wildmenu_pum_term_01.dump
new file mode 100644 (file)
index 0000000..b619875
--- /dev/null
@@ -0,0 +1,10 @@
+| +0&#ffffff0@74
+@75
+@75
+@5| +0#0000001#e0e0e08|d|e|f|i|n|e| @8| +0#0000000#ffffff0@53
+|<+2#ffffff16#00e0003|o|r|t| | +0#0000001#ffd7ff255|j|u|m|p| @10|w+2#ffffff16#00e0003|r|i|t|e|(|s|y|s|.|s|t|d|i|n|.|r|e|a|d|(|)@1|"| |[|r|u|n@1|i|n|g|]| @1|0|,|0|-|1| @9|A|l@1
+| +0#0000000#ffffff0@4| +0#0000001#ffd7ff255|l|i|s|t| @10| +0#0000000#ffffff0@53
+|~+0#4040ff13&| @3| +0#0000001#ffd7ff255|p|l|a|c|e| @9| +0#4040ff13#ffffff0@53
+|~| @3| +0#0000001#ffd7ff255|u|n|d|e|f|i|n|e| @6| +0#4040ff13#ffffff0@53
+|[+1#0000000&|N|o| |N| +0#0000001#ffd7ff255|u|n|p|l|a|c|e| @7| +1#0000000#ffffff0@35|0|,|0|-|1| @9|A|l@1
+|:+0&&|s|i|g|n| |d|e|f|i|n|e> @62
index f2b03decb553e436f4b21557ef3a8e7b76f01f38..e38a56963db7526f4074c831ca35db5c038d54f9 100644 (file)
@@ -2510,6 +2510,30 @@ func Test_wildmenumode_with_pum()
   cunmap <F2>
 endfunc
 
+" Test for opening the cmdline completion popup menu from the terminal window.
+" The popup menu should be positioned correctly over the status line of the
+" bottom-most window.
+func Test_wildmenu_pum_from_terminal()
+  CheckRunVimInTerminal
+  let python = PythonProg()
+  call CheckPython(python)
+
+  %bw!
+  let cmds = ['set wildmenu wildoptions=pum']
+  let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
+  call add(cmds, "call term_start('" .. pcmd .. "')")
+  call writefile(cmds, 'Xtest')
+  let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
+  call term_sendkeys(buf, "\r\r\r")
+  call term_wait(buf)
+  call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
+  call term_wait(buf)
+  call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
+  call term_wait(buf)
+  call StopVimInTerminal(buf)
+  call delete('Xtest')
+endfunc
+
 " Test for completion after a :substitute command followed by a pipe (|)
 " character
 func Test_cmdline_complete_substitute()
index 8e7525847a36067afa3b22712b396cb95e942eff..f290eff3ad51cdf6c1b319eac6921438af783f39 100644 (file)
@@ -935,7 +935,7 @@ func TerminalTmap(remap)
   tunmap 123
   tunmap 456
   call assert_equal('', maparg('123', 't'))
-  close
+  exe buf . 'bwipe'
   unlet g:job
 endfunc
 
index b1b976c824510f0fdff9e1e930c8fbfb5fcd3b3b..dd1331ea9f76d46b512f07b91f71e989511dec22 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4655,
 /**/
     4654,
 /**/