From e12bedbc0f216aebab8ca4b520760b96ba524022 Mon Sep 17 00:00:00 2001 From: MagicDuck Date: Thu, 29 Aug 2024 01:10:17 -0700 Subject: [PATCH] improving perf of force redraw --- lua/grug-far/actions/replace.lua | 2 +- lua/grug-far/actions/search.lua | 2 +- lua/grug-far/actions/sync.lua | 2 +- lua/grug-far/render/resultsList.lua | 8 ++++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lua/grug-far/actions/replace.lua b/lua/grug-far/actions/replace.lua index 0a7617b7..67c545f9 100644 --- a/lua/grug-far/actions/replace.lua +++ b/lua/grug-far/actions/replace.lua @@ -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, }) diff --git a/lua/grug-far/actions/search.lua b/lua/grug-far/actions/search.lua index 93e2b3cd..f576efcb 100644 --- a/lua/grug-far/actions/search.lua +++ b/lua/grug-far/actions/search.lua @@ -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 diff --git a/lua/grug-far/actions/sync.lua b/lua/grug-far/actions/sync.lua index f34ce0c6..9e238bfc 100644 --- a/lua/grug-far/actions/sync.lua +++ b/lua/grug-far/actions/sync.lua @@ -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 diff --git a/lua/grug-far/render/resultsList.lua b/lua/grug-far/render/resultsList.lua index 57e505c8..841bb602 100644 --- a/lua/grug-far/render/resultsList.lua +++ b/lua/grug-far/render/resultsList.lua @@ -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