Skip to content

Commit 06bf178

Browse files
committed
(mini.clue) Update querying process to repeatedly force redraw.
1 parent ff00eec commit 06bf178

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

lua/mini/clue.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,11 @@ H.keys = {
11041104
ctrl_u = vim.api.nvim_replace_termcodes('<C-u>', true, true, true),
11051105
}
11061106

1107+
-- Timers
1108+
H.timers = {
1109+
getcharstr = vim.loop.new_timer(),
1110+
}
1111+
11071112
-- Undo command which depends on Neovim version
11081113
H.undo_autocommand = 'au ModeChanged * ++once undo' .. (vim.fn.has('nvim-0.8') == 1 and '!' or '')
11091114

@@ -1915,8 +1920,13 @@ H.is_valid_buf = function(buf_id) return type(buf_id) == 'number' and vim.api.nv
19151920

19161921
H.is_valid_win = function(win_id) return type(win_id) == 'number' and vim.api.nvim_win_is_valid(win_id) end
19171922

1923+
H.redraw_scheduled = vim.schedule_wrap(function() vim.cmd('redraw') end)
1924+
19181925
H.getcharstr = function()
1926+
-- Ensure redraws still happen
1927+
H.timers.getcharstr:start(0, 50, H.redraw_scheduled)
19191928
local ok, char = pcall(vim.fn.getcharstr)
1929+
H.timers.getcharstr:stop()
19201930
-- Terminate if couldn't get input (like with <C-c>) or it is `<Esc>`
19211931
if not ok or char == '\27' or char == '' then return end
19221932
return H.get_langmap()[char] or char
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--|---------|---------|---------|---------|
2+
01|aaaa
3+
02|~
4+
03|~
5+
04|~
6+
05|~
7+
06|~ ┌<Space>───────────────────────┐
8+
07|~ │ f │ Add hl │
9+
08|~ └──────────────────────────────┘
10+
09|[No Name] [+] 1,1 All
11+
10|
12+
13+
--|---------|---------|---------|---------|
14+
01|0111111111111111111111111111111111111111
15+
02|2222222222222222222222222222222222222222
16+
03|2222222222222222222222222222222222222222
17+
04|2222222222222222222222222222222222222222
18+
05|2222222222222222222222222222222222222222
19+
06|2222222234444444333333333333333333333333
20+
07|2222222235556777777777777777777777777773
21+
08|2222222233333333333333333333333333333333
22+
09|8888888888888888888888888888888888888888
23+
10|3333333333333333333333333333333333333333
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--|---------|---------|---------|---------|
2+
01|aaaa
3+
02|~
4+
03|~
5+
04|~
6+
05|~
7+
06|~ ┌<Space>───────────────────────┐
8+
07|~ │ f │ Add hl │
9+
08|~ └──────────────────────────────┘
10+
09|[No Name] [+] 1,1 All
11+
10|
12+
13+
--|---------|---------|---------|---------|
14+
01|0011111111111111111111111111111111111111
15+
02|2222222222222222222222222222222222222222
16+
03|2222222222222222222222222222222222222222
17+
04|2222222222222222222222222222222222222222
18+
05|2222222222222222222222222222222222222222
19+
06|2222222234444444333333333333333333333333
20+
07|2222222235556777777777777777777777777773
21+
08|2222222233333333333333333333333333333333
22+
09|8888888888888888888888888888888888888888
23+
10|3333333333333333333333333333333333333333

tests/test_clue.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,36 @@ T['Querying keys']['works'] = function()
19161916
eq(get_test_map_count('n', ' f'), 2)
19171917
end
19181918

1919+
T['Querying keys']['does not entirely block redraws'] = function()
1920+
child.set_size(10, 40)
1921+
set_lines({ 'aaaa' })
1922+
child.lua([[
1923+
local ns_id = vim.api.nvim_create_namespace('test')
1924+
local n = 0
1925+
_G.add_hl = function()
1926+
local col = n
1927+
vim.defer_fn(function()
1928+
vim.highlight.range(0, ns_id, 'Comment', { 0, col }, { 0, col + 1 }, {})
1929+
end, 5)
1930+
n = n + 1
1931+
end
1932+
vim.keymap.set('n', '<Space>f', _G.add_hl, { desc = 'Add hl' })]])
1933+
1934+
load_module({
1935+
clues = { { mode = 'n', keys = '<Space>f', postkeys = '<Space>' } },
1936+
triggers = { { mode = 'n', keys = '<Space>' } },
1937+
})
1938+
1939+
type_keys('<Space>', 'f')
1940+
-- - Redraws don't happen immediately but inside a repeating timer
1941+
sleep(50 + 5)
1942+
child.expect_screenshot()
1943+
1944+
type_keys('f')
1945+
sleep(50 + 5)
1946+
child.expect_screenshot()
1947+
end
1948+
19191949
T['Querying keys']['allows trigger with more than one character'] = function()
19201950
make_test_map('n', '<Space>aa')
19211951
load_module({ triggers = { { mode = 'n', keys = '<Space>a' } } })

0 commit comments

Comments
 (0)