mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	Add complete() noinsert/noselect support #2792
This commit is contained in:
		
				
					committed by
					
						
						Scott Prager
					
				
			
			
				
	
			
			
			
						parent
						
							6270d431aa
						
					
				
				
					commit
					be66c0b357
				
			@@ -2250,7 +2250,14 @@ void set_completion(colnr_T startcol, list_T *list)
 | 
			
		||||
  compl_cont_status = 0;
 | 
			
		||||
 | 
			
		||||
  compl_curr_match = compl_first_match;
 | 
			
		||||
  ins_complete(Ctrl_N);
 | 
			
		||||
  if (compl_no_insert) {
 | 
			
		||||
    ins_complete(K_DOWN);
 | 
			
		||||
  } else {
 | 
			
		||||
    ins_complete(Ctrl_N);
 | 
			
		||||
    if (compl_no_select) {
 | 
			
		||||
      ins_complete(Ctrl_P);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  ui_flush();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -2980,16 +2987,17 @@ static int ins_compl_prep(int c)
 | 
			
		||||
    compl_get_longest = (strstr((char *)p_cot, "longest") != NULL);
 | 
			
		||||
    compl_used_match = TRUE;
 | 
			
		||||
 | 
			
		||||
    if (strstr((char *)p_cot, "noselect") != NULL) {
 | 
			
		||||
      compl_no_insert = FALSE;
 | 
			
		||||
      compl_no_select = TRUE;
 | 
			
		||||
    } else if (strstr((char *)p_cot, "noinsert") != NULL) {
 | 
			
		||||
      compl_no_insert = TRUE;
 | 
			
		||||
      compl_no_select = FALSE;
 | 
			
		||||
    } else {
 | 
			
		||||
      compl_no_insert = FALSE;
 | 
			
		||||
      compl_no_select = FALSE;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (strstr((char *)p_cot, "noselect") != NULL) {
 | 
			
		||||
    compl_no_insert = FALSE;
 | 
			
		||||
    compl_no_select = TRUE;
 | 
			
		||||
  } else if (strstr((char *)p_cot, "noinsert") != NULL) {
 | 
			
		||||
    compl_no_insert = TRUE;
 | 
			
		||||
    compl_no_select = FALSE;
 | 
			
		||||
  } else {
 | 
			
		||||
    compl_no_insert = FALSE;
 | 
			
		||||
    compl_no_select = FALSE;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
 | 
			
		||||
local helpers = require('test.functional.helpers')
 | 
			
		||||
local clear, feed, execute = helpers.clear, helpers.feed, helpers.execute
 | 
			
		||||
local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq
 | 
			
		||||
@@ -54,25 +55,42 @@ describe('completion', function()
 | 
			
		||||
    end)
 | 
			
		||||
  end)
 | 
			
		||||
  describe('completeopt', function()
 | 
			
		||||
    before_each(function()
 | 
			
		||||
      source([[
 | 
			
		||||
      function! TestComplete() abort
 | 
			
		||||
        call complete(1, ['foo'])
 | 
			
		||||
        return ''
 | 
			
		||||
      endfunction
 | 
			
		||||
      ]])
 | 
			
		||||
    end)
 | 
			
		||||
 | 
			
		||||
    it('inserts the first candidate if default', function()
 | 
			
		||||
      execute('set completeopt+=menuone')
 | 
			
		||||
      feed('ifoo<ESC>o<C-x><C-n>bar<ESC>')
 | 
			
		||||
      eq('foobar', eval('getline(2)'))
 | 
			
		||||
      feed('o<C-r>=TestComplete()<CR><ESC>')
 | 
			
		||||
      eq('foo', eval('getline(3)'))
 | 
			
		||||
    end)
 | 
			
		||||
    it('selects the first candidate if noinsert', function()
 | 
			
		||||
      execute('set completeopt+=menuone,noinsert')
 | 
			
		||||
      feed('ifoo<ESC>o<C-x><C-n><C-y><ESC>')
 | 
			
		||||
      eq('foo', eval('getline(2)'))
 | 
			
		||||
      feed('o<C-r>=TestComplete()<CR><C-y><ESC>')
 | 
			
		||||
      eq('foo', eval('getline(3)'))
 | 
			
		||||
    end)
 | 
			
		||||
    it('does not insert the first candidate if noselect', function()
 | 
			
		||||
      execute('set completeopt+=menuone,noselect')
 | 
			
		||||
      feed('ifoo<ESC>o<C-x><C-n>bar<ESC>')
 | 
			
		||||
      eq('bar', eval('getline(2)'))
 | 
			
		||||
      feed('o<C-r>=TestComplete()<CR>bar<ESC>')
 | 
			
		||||
      eq('bar', eval('getline(3)'))
 | 
			
		||||
    end)
 | 
			
		||||
    it('does not select/insert the first candidate if noselect and noinsert', function()
 | 
			
		||||
      execute('set completeopt+=menuone,noselect,noinsert')
 | 
			
		||||
      feed('ifoo<ESC>o<C-x><C-n><ESC>')
 | 
			
		||||
      eq('', eval('getline(2)'))
 | 
			
		||||
      feed('o<C-r>=TestComplete()<CR><ESC>')
 | 
			
		||||
      eq('', eval('getline(3)'))
 | 
			
		||||
    end)
 | 
			
		||||
  end)
 | 
			
		||||
end)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user