search: snippets at utf-8 boundaries

This commit is contained in:
Kartik K. Agaram 2022-09-02 09:28:54 -07:00
parent 2aa729907c
commit df4d712208

View File

@ -884,7 +884,9 @@ function search_in_file(filename)
if index == nil then
break
end
local snippet = contents:sub(math.max(1, index-100), math.min(#contents, index+100))
local start_offset = find_previous_byte(contents, '\n', index)
local end_offset = contents:find('\n', index, --[[literal]] true)
local snippet = contents:sub(start_offset, end_offset)
local success, errmsg = love.filesystem.append(outfilename, '...'..snippet..'...\n\n')
if not success then error(errmsg) end
end
@ -895,6 +897,16 @@ function search_in_file(filename)
end
end
function find_previous_byte(s, b, index)
while index > 1 do
if s:sub(index, index) == b then
break
end
index = index-1
end
return index
end
function interrupt_search_all()
if Display_settings.search_all_state then
local id = id_for_search_all_pane(Display_settings.search_all_query)