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

Commit

Permalink
fix: mutiline pattern
Browse files Browse the repository at this point in the history
Only search the first line of the pattern if it contains multiple lines.
  • Loading branch information
luckasRanarison committed Sep 26, 2023
1 parent 0416494 commit 8e0cb37
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lua/nvim-devdocs/operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ M.get_all_entries = function()
return entries
end

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

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

local filtered_lines = {}
local found = false
local search_pattern = create_pattern(pattern)
local pattern_lines = vim.split(pattern, "\n")
local search_pattern = create_pattern(pattern_lines[1]) -- only search the first line
local split = vim.split(pattern, " ")
local header = split[1]
local top_header = header and header:sub(1, #header - 1)

for _, line in ipairs(lines) do
if found and header then
if found then
local line_split = vim.split(line, " ")
local first = line_split[1]
if first and first == header or first == top_header then break end
if first == header or first == top_header then break end
end
if line:match(search_pattern) then found = true end
if found then table.insert(filtered_lines, line) end
Expand Down

0 comments on commit 8e0cb37

Please sign in to comment.