From efa664c7ed21b63f2cf0a8caa53161fe7e32b2bb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Jan 2025 14:39:13 +0800 Subject: vim-patch:9.1.1056: Vim doesn't highlight to be inserted text when completing (#32251) Problem: Vim doesn't highlight to be inserted text when completing Solution: Add support for the "preinsert" 'completeopt' value (glepnir) Support automatically inserting the currently selected candidate word that does not belong to the latter part of the leader. fixes: vim/vim#3433 closes: vim/vim#16403 https://github.com/vim/vim/commit/edd4ac3e895ce16034c7e098f1d68e0155d97886 Co-authored-by: glepnir --- test/old/testdir/gen_opt_test.vim | 4 +- test/old/testdir/test_ins_complete.vim | 117 +++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/old/testdir/gen_opt_test.vim b/test/old/testdir/gen_opt_test.vim index bcb0f3d4c4..f9fcc4ae1b 100644 --- a/test/old/testdir/gen_opt_test.vim +++ b/test/old/testdir/gen_opt_test.vim @@ -87,7 +87,7 @@ let test_values = { \ ['xxx', 'help,nofile']], \ 'clipboard': [['', 'unnamed'], ['xxx', '\ze*', 'exclude:\\%(']], \ 'completeopt': [['', 'menu', 'menuone', 'longest', 'preview', 'popup', - \ 'noinsert', 'noselect', 'fuzzy', 'menu,longest'], + \ 'noinsert', 'noselect', 'fuzzy', 'preinsert', 'menu,longest'], \ ['xxx', 'menu,,,longest,']], \ 'encoding': [['utf8'], []], \ 'foldcolumn': [[0, 1, 4, 'auto', 'auto:1', 'auto:9'], [-1, 13, 999]], @@ -186,7 +186,7 @@ let test_values = { \ ['xxx']], \ 'concealcursor': [['', 'n', 'v', 'i', 'c', 'nvic'], ['xxx']], "\ 'completeopt': [['', 'menu', 'menuone', 'longest', 'preview', 'popup', - "\ " 'popuphidden', 'noinsert', 'noselect', 'fuzzy', 'menu,longest'], + "\ " 'popuphidden', 'noinsert', 'noselect', 'fuzzy', 'preinsert', 'menu,longest'], "\ " ['xxx', 'menu,,,longest,']], \ 'completeitemalign': [['abbr,kind,menu', 'menu,abbr,kind'], \ ['', 'xxx', 'abbr', 'abbr,menu', 'abbr,menu,kind,abbr', diff --git a/test/old/testdir/test_ins_complete.vim b/test/old/testdir/test_ins_complete.vim index 1c63e8f4cc..969d5012f4 100644 --- a/test/old/testdir/test_ins_complete.vim +++ b/test/old/testdir/test_ins_complete.vim @@ -2964,4 +2964,121 @@ func Test_complete_info_completed() set cot& endfunc +function Test_completeopt_preinsert() + func Omni_test(findstart, base) + if a:findstart + return col(".") + endif + return [#{word: "fobar"}, #{word: "foobar"}, #{word: "你的"}, #{word: "你好世界"}] + endfunc + set omnifunc=Omni_test + set completeopt=menu,menuone,preinsert + + new + call feedkeys("S\\f", 'tx') + call assert_equal("fobar", getline('.')) + call feedkeys("\\", 'tx') + + call feedkeys("S\\foo", 'tx') + call assert_equal("foobar", getline('.')) + call feedkeys("\\", 'tx') + + call feedkeys("S\\foo\\\", 'tx') + call assert_equal("", getline('.')) + call feedkeys("\\", 'tx') + + " delete a character and input new leader + call feedkeys("S\\foo\b", 'tx') + call assert_equal("fobar", getline('.')) + call feedkeys("\\", 'tx') + + " delete preinsert when prepare completion + call feedkeys("S\\f\", 'tx') + call assert_equal("f ", getline('.')) + call feedkeys("\\", 'tx') + + call feedkeys("S\\你", 'tx') + call assert_equal("你的", getline('.')) + call feedkeys("\\", 'tx') + + call feedkeys("S\\你好", 'tx') + call assert_equal("你好世界", getline('.')) + call feedkeys("\\", 'tx') + + call feedkeys("Shello wo\\\\\f", 'tx') + call assert_equal("hello fobar wo", getline('.')) + call feedkeys("\\", 'tx') + + call feedkeys("Shello wo\\\\\f\", 'tx') + call assert_equal("hello wo", getline('.')) + call feedkeys("\\", 'tx') + + call feedkeys("Shello wo\\\\\foo", 'tx') + call assert_equal("hello foobar wo", getline('.')) + call feedkeys("\\", 'tx') + + call feedkeys("Shello wo\\\\\foo\b", 'tx') + call assert_equal("hello fobar wo", getline('.')) + call feedkeys("\\", 'tx') + + " confrim + call feedkeys("S\\f\", 'tx') + call assert_equal("fobar", getline('.')) + call assert_equal(5, col('.')) + + " cancel + call feedkeys("S\\fo\", 'tx') + call assert_equal("fo", getline('.')) + call assert_equal(2, col('.')) + + call feedkeys("S hello hero\h\\", 'tx') + call assert_equal("hello", getline('.')) + call assert_equal(1, col('.')) + + call feedkeys("Sh\\\", 'tx') + call assert_equal("hello", getline('.')) + call assert_equal(5, col('.')) + + " delete preinsert part + call feedkeys("S\\fo ", 'tx') + call assert_equal("fo ", getline('.')) + call assert_equal(3, col('.')) + + " whole line + call feedkeys("Shello hero\\\", 'tx') + call assert_equal("hello hero", getline('.')) + call assert_equal(1, col('.')) + + call feedkeys("Shello hero\he\\", 'tx') + call assert_equal("hello hero", getline('.')) + call assert_equal(2, col('.')) + + " can not work with fuzzy + set cot+=fuzzy + call feedkeys("S\\", 'tx') + call assert_equal("fobar", getline('.')) + call assert_equal(5, col('.')) + + " test for fuzzy and noinsert + set cot+=noinsert + call feedkeys("S\\fb", 'tx') + call assert_equal("fb", getline('.')) + call assert_equal(2, col('.')) + + call feedkeys("S\\你", 'tx') + call assert_equal("你", getline('.')) + call assert_equal(1, col('.')) + + call feedkeys("S\\fb\", 'tx') + call assert_equal("fobar", getline('.')) + call assert_equal(5, col('.')) + + bw! + bw! + set cot& + set omnifunc& + delfunc Omni_test + autocmd! CompleteChanged +endfunc + " vim: shiftwidth=2 sts=2 expandtab nofoldenable -- cgit