Skip to content

Commit

Permalink
improving perf of force redraw
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicDuck committed Aug 29, 2024
1 parent 0d5ffde commit e12bedb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lua/grug-far/actions/replace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ local function replace(params)
state.actionMessage = update.message
end
renderResultsHeader(buf, context)
resultsList.throttledForceRedrawBuffer(buf)
resultsList.throttledForceRedrawBuffer(buf, context)
end,
on_finish = on_finish_all,
})
Expand Down
2 changes: 1 addition & 1 deletion lua/grug-far/actions/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ local function search(params)
renderResultsHeader(buf, context)

resultsList.appendResultsChunk(buf, context, data)
resultsList.throttledForceRedrawBuffer(buf)
resultsList.throttledForceRedrawBuffer(buf, context)

if shouldAbortEarly then
if state.abort.search then
Expand Down
2 changes: 1 addition & 1 deletion lua/grug-far/actions/sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ local function sync(params)
end
state.actionMessage = getActionMessage(nil, changesCount, changesTotal)
renderResultsHeader(buf, context)
resultsList.throttledForceRedrawBuffer(buf)
resultsList.throttledForceRedrawBuffer(buf, context)
end,
on_finish = function(status, errorMessage, customActionMessage)
if state.bufClosed then
Expand Down
8 changes: 6 additions & 2 deletions lua/grug-far/render/resultsList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,16 @@ end

--- force redraws buffer. This is order to apear more responsive to the user
--- and quickly give user feedback as results come in / data is updated
--- note that only the "top" range of lines is redrawn, including a bunch of lines
--- after headerRow so that we immediately get error messages to show up
---@param buf integer
function M.forceRedrawBuffer(buf)
---@param context GrugFarContext
function M.forceRedrawBuffer(buf, context)
---@diagnostic disable-next-line
if vim.api.nvim__redraw then
---@diagnostic disable-next-line
vim.api.nvim__redraw({ buf = buf, flush = true })
vim.api.nvim__redraw({ buf = buf, flush = true, range = { 0, context.state.headerRow + 100 } })
-- vim.api.nvim__redraw({ buf = buf, flush = true })
end
end

Expand Down

0 comments on commit e12bedb

Please sign in to comment.