aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-05-24 15:45:07 +0800
committerGitHub <noreply@github.com>2024-05-24 15:45:07 +0800
commit4f431bb632b5285fc0f0d5e6ac0ff21b7c6ef101 (patch)
treee0193fffc261bcb1ca85c2140546e7d50469314d
parentcd05fbef170b29083973fd11170d25225feb8bed (diff)
downloadrneovim-4f431bb632b5285fc0f0d5e6ac0ff21b7c6ef101.tar.gz
rneovim-4f431bb632b5285fc0f0d5e6ac0ff21b7c6ef101.tar.bz2
rneovim-4f431bb632b5285fc0f0d5e6ac0ff21b7c6ef101.zip
vim-patch:9.1.0439: Cannot filter the history (#28958)
Problem: Cannot filter the history Solution: Implement :filter :history closes: vim/vim#14835 https://github.com/vim/vim/commit/42a5b5a6d0d05255b9c464abe71f29c7677b5833 Co-authored-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--runtime/doc/various.txt1
-rw-r--r--src/nvim/cmdhist.c3
-rw-r--r--test/old/testdir/test_history.vim54
3 files changed, 57 insertions, 1 deletions
diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt
index 662be4a7a2..0287271d4c 100644
--- a/runtime/doc/various.txt
+++ b/runtime/doc/various.txt
@@ -400,6 +400,7 @@ gx Opens the current filepath or URL (decided by
|:command| - filter by command name
|:files| - filter by file name
|:highlight| - filter by highlight group
+ |:history| - filter by history commands
|:jumps| - filter by file name
|:let| - filter by variable name
|:list| - filter whole line
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c
index eb1658aa1f..983ab8b59b 100644
--- a/src/nvim/cmdhist.c
+++ b/src/nvim/cmdhist.c
@@ -662,7 +662,8 @@ void ex_history(exarg_T *eap)
i = 0;
}
if (hist[i].hisstr != NULL
- && hist[i].hisnum >= j && hist[i].hisnum <= k) {
+ && hist[i].hisnum >= j && hist[i].hisnum <= k
+ && !message_filtered(hist[i].hisstr)) {
msg_putchar('\n');
snprintf(IObuff, IOSIZE, "%c%6d ", i == idx ? '>' : ' ',
hist[i].hisnum);
diff --git a/test/old/testdir/test_history.vim b/test/old/testdir/test_history.vim
index 19490f2528..b288abc3f6 100644
--- a/test/old/testdir/test_history.vim
+++ b/test/old/testdir/test_history.vim
@@ -96,6 +96,60 @@ function Test_History()
call assert_fails('history xyz', 'E488:')
call assert_fails('history ,abc', 'E488:')
call assert_fails('call histdel(":", "\\%(")', 'E53:')
+
+ " Test for filtering the history list
+ let hist_filter = execute(':filter /_\d/ :history all')->split('\n')
+ call assert_equal(20, len(hist_filter))
+ let expected = [' # cmd history',
+ \ ' 2 text_2',
+ \ ' 3 text_3',
+ \ '> 4 text_4',
+ \ ' # search history',
+ \ ' 2 text_2',
+ \ ' 3 text_3',
+ \ '> 4 text_4',
+ \ ' # expr history',
+ \ ' 2 text_2',
+ \ ' 3 text_3',
+ \ '> 4 text_4',
+ \ ' # input history',
+ \ ' 2 text_2',
+ \ ' 3 text_3',
+ \ '> 4 text_4',
+ \ ' # debug history',
+ \ ' 2 text_2',
+ \ ' 3 text_3',
+ \ '> 4 text_4']
+ call assert_equal(expected, hist_filter)
+
+ let cmds = {'c': 'cmd', 's': 'search', 'e': 'expr', 'i': 'input', 'd': 'debug'}
+ for h in sort(keys(cmds))
+ " find some items
+ let hist_filter = execute(':filter /_\d/ :history ' .. h)->split('\n')
+ call assert_equal(4, len(hist_filter))
+
+ let expected = [' # ' .. cmds[h] .. ' history',
+ \ ' 2 text_2',
+ \ ' 3 text_3',
+ \ '> 4 text_4']
+ call assert_equal(expected, hist_filter)
+
+ " Search for an item that is not there
+ let hist_filter = execute(':filter /XXXX/ :history ' .. h)->split('\n')
+ call assert_equal(1, len(hist_filter))
+
+ let expected = [' # ' .. cmds[h] .. ' history']
+ call assert_equal(expected, hist_filter)
+
+ " Invert the filter condition, find non-matches
+ let hist_filter = execute(':filter! /_3$/ :history ' .. h)->split('\n')
+ call assert_equal(3, len(hist_filter))
+
+ let expected = [' # ' .. cmds[h] .. ' history',
+ \ ' 2 text_2',
+ \ '> 4 text_4']
+ call assert_equal(expected, hist_filter)
+ endfor
endfunction
function Test_history_truncates_long_entry()