Mercurial > vim
view src/testdir/screendump.vim @ 33674:021e5bb88513 v9.0.2074
patch 9.0.2074: Completion menu may be wrong
Commit: https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c
Author: Christian Brabandt <cb@256bit.org>
Date: Fri Oct 27 19:16:26 2023 +0200
patch 9.0.2074: Completion menu may be wrong
Problem: Completion menu may be wrong
Solution: Check for the original direction of the completion menu,
add more tests, make it work with 'noselect'
completion: move in right direction when filling completion_info()
When moving through the insert completion menu and switching directions,
we need to make sure we start at the correct position in the list and
move correctly forward/backwards through it, so that we do not skip
entries and the selected item points to the correct entry in the list
of completion entries generated by the completion_info() function.
The general case is this:
1) CTRL-X CTRL-N, we will traverse the list starting from
compl_first_match and then go forwards (using the cp->next pointer)
through the list (skipping the very first entry, which has the
CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry
2) CTRL-X CTRL-P, we will traverse the list starting from
compl_first_match (which now points to the last entry). The previous
entry will have the CP_ORIGINAL_TEXT flag set, so we need to start
traversing the list from the second prev pointer.
There are in fact 2 special cases after starting the completion menu
with CTRL-X:
3) CTRL-N and then going backwards by pressing CTRL-P again.
compl_first_match will point to the same entry as in step 1 above,
but since compl_dir_foward() has been switched by pressing CTRL-P
to backwards we need to pretend to be in still in case 1 and still
traverse the list in forward direction using the cp_next pointer
4) CTRL-P and then going forwards by pressing CTRL-N again.
compl_first_match will point to the same entry as in step 2 above,
but since compl_dir_foward() has been switched by pressing CTRL-N
to forwards we need to pretend to be in still in case 2 and still
traverse the list in backward direction using the cp_prev pointer
For the 'noselect' case however, this is slightly different again. When
going backwards, we only need to go one cp_prev pointer back. And
resting of the direction works again slightly different. So we need to
take the noselect option into account when deciding in which direction
to iterate through the list of matches.
related: #13402
related: #12971
closes: #13408
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 27 Oct 2023 19:30:05 +0200 |
parents | 4a88061200c2 |
children | 9d1ff79eebbb |
line wrap: on
line source
" Functions shared by tests making screen dumps. " Only load this script once. if exists('*VerifyScreenDump') finish endif source shared.vim source term_util.vim " Skip the rest if there is no terminal feature at all. if !has('terminal') finish endif " Read a dump file "fname" and if "filter" exists apply it to the text. def ReadAndFilter(fname: string, filter: string): list<string> var contents = readfile(fname) if filereadable(filter) # do this in the bottom window so that the terminal window is unaffected wincmd j enew setline(1, contents) exe "source " .. filter contents = getline(1, '$') enew! wincmd k redraw endif return contents enddef " Verify that Vim running in terminal buffer "buf" matches the screen dump. " "options" is passed to term_dumpwrite(). " Additionally, the "wait" entry can specify the maximum time to wait for the " screen dump to match in msec (default 1000 msec). " The file name used is "dumps/{filename}.dump". " " To ignore part of the dump, provide a "dumps/{filename}.vim" file with " Vim commands to be applied to both the reference and the current dump, so " that parts that are irrelevant are not used for the comparison. The result " is NOT written, thus "term_dumpdiff()" shows the difference anyway. " " Optionally an extra argument can be passed which is prepended to the error " message. Use this when using the same dump file with different options. " Returns non-zero when verification fails. func VerifyScreenDump(buf, filename, options, ...) let reference = 'dumps/' . a:filename . '.dump' let filter = 'dumps/' . a:filename . '.vim' let testfile = 'failed/' . a:filename . '.dump' let max_loops = get(a:options, 'wait', 1000) / 10 " Starting a terminal to make a screendump is always considered flaky. let g:test_is_flaky = 1 " wait for the pending updates to be handled. call TermWait(a:buf) " Redraw to execute the code that updates the screen. Otherwise we get the " text and attributes only from the internal buffer. redraw if filereadable(reference) let refdump = ReadAndFilter(reference, filter) else " Must be a new screendump, always fail let refdump = [] endif let did_mkdir = 0 if !isdirectory('failed') let did_mkdir = 1 call mkdir('failed') endif let i = 0 while 1 " leave some time for updating the original window sleep 10m call delete(testfile) call term_dumpwrite(a:buf, testfile, a:options) let testdump = ReadAndFilter(testfile, filter) if refdump == testdump call delete(testfile) if did_mkdir call delete('failed', 'd') endif break endif if i == max_loops " Leave the failed dump around for inspection. if filereadable(reference) let msg = 'See dump file difference: call term_dumpdiff("testdir/' .. testfile .. '", "testdir/' .. reference .. '")' if a:0 == 1 let msg = a:1 . ': ' . msg endif if len(testdump) != len(refdump) let msg = msg . '; line count is ' . len(testdump) . ' instead of ' . len(refdump) endif else let msg = 'See new dump file: call term_dumpload("testdir/' .. testfile .. '")' " no point in retrying let g:run_nr = 10 endif for i in range(len(refdump)) if i >= len(testdump) break endif if testdump[i] != refdump[i] let msg = msg . '; difference in line ' . (i + 1) . ': "' . testdump[i] . '"' endif endfor call assert_report(msg) return 1 endif let i += 1 endwhile return 0 endfunc