diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-08-31 04:03:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-31 04:03:30 +0800 |
commit | 55dc482e757e1d8f7713daa61a2deddfdaca4e42 (patch) | |
tree | a66615fae1d725e0fdad5c21630fd8fb58df4a34 /test | |
parent | 42ed0ffad9851f3794a9dff080a2789c87c6d7c8 (diff) | |
download | rneovim-55dc482e757e1d8f7713daa61a2deddfdaca4e42.tar.gz rneovim-55dc482e757e1d8f7713daa61a2deddfdaca4e42.tar.bz2 rneovim-55dc482e757e1d8f7713daa61a2deddfdaca4e42.zip |
fix(completion): fix inconsistent Enter behavior (#30196)
Problem: Behavior of Enter in completion depends on typing speed.
Solution: Don't make whether Enter selects original text depend on
whether completion has been interrupted, which can happen
interactively with a slow completion function.
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/editor/completion_spec.lua | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 9d5bda0acc..3f19596bd7 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -327,7 +327,7 @@ describe('completion', function() end end) - describe('refresh:always', function() + describe('with refresh:always and noselect', function() before_each(function() source([[ function! TestCompletion(findstart, base) abort @@ -459,6 +459,67 @@ describe('completion', function() June June]]) end) + + it('Enter does not select original text', function() + feed('iJ<C-x><C-u>') + poke_eventloop() + feed('u') + poke_eventloop() + feed('<CR>') + expect([[ + Ju + ]]) + feed('J<C-x><C-u>') + poke_eventloop() + feed('<CR>') + expect([[ + Ju + J + ]]) + end) + end) + + describe('with noselect but not refresh:always', function() + before_each(function() + source([[ + function! TestCompletion(findstart, base) abort + if a:findstart + let line = getline('.') + let start = col('.') - 1 + while start > 0 && line[start - 1] =~ '\a' + let start -= 1 + endwhile + return start + else + let ret = [] + for m in split("January February March April May June July August September October November December") + if m =~ a:base " match by regex + call add(ret, m) + endif + endfor + return {'words':ret} + endif + endfunction + + set completeopt=menuone,noselect + set completefunc=TestCompletion + ]]) + end) + + it('Enter selects original text after adding leader', function() + feed('iJ<C-x><C-u>') + poke_eventloop() + feed('u') + poke_eventloop() + feed('<CR>') + expect('Ju') + feed('<Esc>') + poke_eventloop() + -- The behavior should be the same when completion has been interrupted, + -- which can happen interactively if the completion function is slow. + feed('SJ<C-x><C-u>u<CR>') + expect('Ju') + end) end) describe('with a lot of items', function() |