From 85d0d684dec52095f1c73f9914754ad042e81da6 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 17 May 2021 03:16:20 -0400 Subject: [PATCH] Truncated lines longer than 256 characters, and skipped to the relevant portion of the line to reduce slowdown and increase relevancy. (#185) --- data/plugins/projectsearch.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/data/plugins/projectsearch.lua b/data/plugins/projectsearch.lua index ef887b41..ed818bf6 100644 --- a/data/plugins/projectsearch.lua +++ b/data/plugins/projectsearch.lua @@ -30,7 +30,10 @@ local function find_all_matches_in_file(t, filename, fn) for line in fp:lines() do local s = fn(line) if s then - table.insert(t, { file = filename, text = line, line = n, col = s }) + -- Insert maximum 256 characters. If we insert more, for compiled files, which can have very long lines + -- things tend to get sluggish. If our line is longer than 80 characters, begin to truncate the thing. + local start_index = math.max(s - 80, 1) + table.insert(t, { file = filename, text = (start_index > 1 and "..." or "") .. line:sub(start_index, 256 + start_index), line = n, col = s }) core.redraw = true end if n % 100 == 0 then coroutine.yield() end