Skip to content

Commit

Permalink
(mini.hipatterns) Fix error after deleting first line in a buffer.
Browse files Browse the repository at this point in the history
Details:
- Resolves #536.
  • Loading branch information
echasnovski committed Oct 23, 2023
1 parent 35e29f7 commit 66e3cdc
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 29 deletions.
6 changes: 4 additions & 2 deletions lua/mini/hipatterns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ MiniHipatterns.disable = function(buf_id)
H.cache[buf_id] = nil

vim.api.nvim_del_augroup_by_id(buf_cache.augroup)
vim.api.nvim_buf_clear_namespace(buf_id, H.ns_id.highlight, 0, -1)
H.clear_namespace(buf_id, H.ns_id.highlight, 0, -1)
end

--- Toggle highlighting in buffer
Expand Down Expand Up @@ -825,7 +825,7 @@ H.process_buffer_changes = vim.schedule_wrap(function(buf_id, lines_to_process)
-- Remove current highlights
local ns = H.ns_id.highlight
for l_num, _ in pairs(lines_to_process) do
vim.api.nvim_buf_clear_namespace(buf_id, ns, l_num - 1, l_num)
H.clear_namespace(buf_id, ns, l_num - 1, l_num)
end

-- Add new highlights
Expand Down Expand Up @@ -919,6 +919,8 @@ H.get_line =

H.set_extmark = function(...) pcall(vim.api.nvim_buf_set_extmark, ...) end

H.clear_namespace = function(...) pcall(vim.api.nvim_buf_clear_namespace, ...) end

H.always_true = function() return true end

H.cuberoot = function(x) return math.pow(x, 0.333333) end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
--|---------|-----
01|xxx
01|abcd Hello
02|xxx
03|abcd Hello
04|xxx
03|xxx
04|abcd Hello
05|xxx
06|~
07|~
06|xxx
07|abcd Hello
08|~
09|<e] [+] 1,1 All
10|

--|---------|-----
01|000000000000000
01|000000000011111
02|000000000000000
03|000000000011111
04|000000000000000
03|000000000000000
04|000000000011111
05|000000000000000
06|222222222222222
07|222222222222222
06|000000000000000
07|000000000011111
08|222222222222222
09|333333333333333
10|444444444444444
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
--|---------|-----
01|xxx
02|xxx
03|xxx
03|abcd Hello
04|xxx
05|~
06|~
05|xxx
06|abcd Hello
07|~
08|~
09|<e] [+] 3,1 All
09|<e] [+] 1,1 All
10|

--|---------|-----
01|000000000000000
02|000000000000000
03|000000000000000
03|000000000011111
04|000000000000000
05|111111111111111
06|111111111111111
07|111111111111111
08|111111111111111
09|222222222222222
10|333333333333333
05|000000000000000
06|000000000011111
07|222222222222222
08|222222222222222
09|333333333333333
10|444444444444444
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--|---------|-----
01|xxx
02|xxx
03|xxx
04|xxx
05|abcd Hello
06|~
07|~
08|~
09|<e] [+] 3,1 All
10|

--|---------|-----
01|000000000000000
02|000000000000000
03|000000000000000
04|000000000000000
05|000000000011111
06|222222222222222
07|222222222222222
08|222222222222222
09|333333333333333
10|444444444444444
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--|---------|-----
01|xxx
02|xxx
03|xxx
04|xxx
05|~
06|~
07|~
08|~
09|<e] [+] 4,1 All
10|

--|---------|-----
01|000000000000000
02|000000000000000
03|000000000000000
04|000000000000000
05|111111111111111
06|111111111111111
07|111111111111111
08|111111111111111
09|222222222222222
10|333333333333333
18 changes: 12 additions & 6 deletions tests/test_hipatterns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ T['enable()']['reacts to window scroll'] = function()
end

T['enable()']['reacts to delete of line with match'] = function()
set_lines({ 'xxx', 'xxx', 'abcd', 'xxx', 'xxx' })
set_lines({ 'abcd', 'xxx', 'xxx', 'abcd', 'xxx', 'xxx', 'abcd' })

local hi_abcd = {
pattern = 'abcd',
Expand All @@ -365,13 +365,19 @@ T['enable()']['reacts to delete of line with match'] = function()
local config = { highlighters = { abcd = hi_abcd }, delay = { text_change = 30, scroll = 10 } }
enable(0, config)

sleep(30 + 2)
sleep(30 + small_time)
child.expect_screenshot()

child.api.nvim_win_set_cursor(0, { 3, 0 })
type_keys('dd')
sleep(30 + 2)
child.expect_screenshot()
local validate = function(line_to_delete)
child.api.nvim_win_set_cursor(0, { line_to_delete, 0 })
type_keys('dd')
sleep(30 + small_time)
child.expect_screenshot()
end

validate(1)
validate(3)
validate(5)
end

T['Highlighters'] = new_set()
Expand Down

0 comments on commit 66e3cdc

Please sign in to comment.