Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 8e0cb37

Browse files
fix: mutiline pattern
Only search the first line of the pattern if it contains multiple lines.
1 parent 0416494 commit 8e0cb37

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lua/nvim-devdocs/operations.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ M.get_all_entries = function()
180180
return entries
181181
end
182182

183+
-- if we have a pattern to search for, only consider lines after the pattern
183184
M.filter_doc = function(lines, pattern)
184185
if not pattern then return lines end
185186

@@ -188,16 +189,17 @@ M.filter_doc = function(lines, pattern)
188189

189190
local filtered_lines = {}
190191
local found = false
191-
local search_pattern = create_pattern(pattern)
192+
local pattern_lines = vim.split(pattern, "\n")
193+
local search_pattern = create_pattern(pattern_lines[1]) -- only search the first line
192194
local split = vim.split(pattern, " ")
193195
local header = split[1]
194196
local top_header = header and header:sub(1, #header - 1)
195197

196198
for _, line in ipairs(lines) do
197-
if found and header then
199+
if found then
198200
local line_split = vim.split(line, " ")
199201
local first = line_split[1]
200-
if first and first == header or first == top_header then break end
202+
if first == header or first == top_header then break end
201203
end
202204
if line:match(search_pattern) then found = true end
203205
if found then table.insert(filtered_lines, line) end

0 commit comments

Comments
 (0)