]> granicus.if.org Git - vim/commitdiff
patch 8.2.1901: variable completion does not work in command line window v8.2.1901
authorBram Moolenaar <Bram@vim.org>
Sun, 25 Oct 2020 12:22:42 +0000 (13:22 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 25 Oct 2020 12:22:42 +0000 (13:22 +0100)
Problem:    Variable completion does not work in command line window.
Solution:   Use the "prevwin". (closes #7198)

src/evalvars.c
src/testdir/test_ins_complete.vim
src/version.c

index 1f418ae22848af2a056a5cb523600bb34fd9d786..a5db6e9523697bddfd9d2299e0bd4ac3c08eaf52 100644 (file)
@@ -1981,7 +1981,13 @@ get_user_var_name(expand_T *xp, int idx)
     }
 
     // b: variables
-    ht = &curbuf->b_vars->dv_hashtab;
+    ht =
+#ifdef FEAT_CMDWIN
+       // In cmdwin, the alternative buffer should be used.
+       (cmdwin_type != 0 && get_cmdline_type() == NUL) ?
+       &prevwin->w_buffer->b_vars->dv_hashtab :
+#endif
+       &curbuf->b_vars->dv_hashtab;
     if (bdone < ht->ht_used)
     {
        if (bdone++ == 0)
@@ -1994,7 +2000,13 @@ get_user_var_name(expand_T *xp, int idx)
     }
 
     // w: variables
-    ht = &curwin->w_vars->dv_hashtab;
+    ht =
+#ifdef FEAT_CMDWIN
+       // In cmdwin, the alternative window should be used.
+       (cmdwin_type != 0 && get_cmdline_type() == NUL) ?
+       &prevwin->w_vars->dv_hashtab :
+#endif
+       &curwin->w_vars->dv_hashtab;
     if (wdone < ht->ht_used)
     {
        if (wdone++ == 0)
index 005e14caf091077541bf9e42a0fa3cf0f329642d..8c676e22a97d22c4dad4085d91aec06b33e0d181 100644 (file)
@@ -346,7 +346,10 @@ func Test_compl_in_cmdwin()
   set wildmenu wildchar=<Tab>
   com! -nargs=1 -complete=command GetInput let input = <q-args>
   com! -buffer TestCommand echo 'TestCommand'
+  let w:test_winvar = 'winvar'
+  let b:test_bufvar = 'bufvar'
 
+  " User-defined commands
   let input = ''
   call feedkeys("q:iGetInput T\<C-x>\<C-v>\<CR>", 'tx!')
   call assert_equal('TestCommand', input)
@@ -355,8 +358,30 @@ func Test_compl_in_cmdwin()
   call feedkeys("q::GetInput T\<Tab>\<CR>:q\<CR>", 'tx!')
   call assert_equal('T', input)
 
+
+  com! -nargs=1 -complete=var GetInput let input = <q-args>
+  " Window-local variables
+  let input = ''
+  call feedkeys("q:iGetInput w:test_\<C-x>\<C-v>\<CR>", 'tx!')
+  call assert_equal('w:test_winvar', input)
+
+  let input = ''
+  call feedkeys("q::GetInput w:test_\<Tab>\<CR>:q\<CR>", 'tx!')
+  call assert_equal('w:test_', input)
+
+  " Buffer-local variables
+  let input = ''
+  call feedkeys("q:iGetInput b:test_\<C-x>\<C-v>\<CR>", 'tx!')
+  call assert_equal('b:test_bufvar', input)
+
+  let input = ''
+  call feedkeys("q::GetInput b:test_\<Tab>\<CR>:q\<CR>", 'tx!')
+  call assert_equal('b:test_', input)
+
   delcom TestCommand
   delcom GetInput
+  unlet w:test_winvar
+  unlet b:test_bufvar
   set wildmenu& wildchar&
 endfunc
 
index 7aa2e10e6243ca3b33e220071a0df485fad87ba9..5a36f0651e1e22a2b0df6125d65746de1cbb33e8 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1901,
 /**/
     1900,
 /**/