Skip to content

Commit

Permalink
fix(log): prevent cursor autoscroll spam
Browse files Browse the repository at this point in the history
by adding in a once option to the notify helper which if true calls
api.notify_once.

fixes #252
closes #253
Co-authored-by: martyfurhy <[email protected]>
  • Loading branch information
akinsho committed May 4, 2023
1 parent 8d359be commit 1891476
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lua/flutter-tools/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ local function autoscroll(buf, target_win)
local buf_length = api.nvim_buf_line_count(buf)
local success, err = pcall(api.nvim_win_set_cursor, win, { buf_length, 0 })
if not success then
ui.notify(fmt("Failed to set cursor for log window %s: %s", win, err), ui.ERROR)
ui.notify(fmt("Failed to set cursor for log window %s: %s", win, err), ui.ERROR, {
once = true,
})
end
end

Expand Down
16 changes: 8 additions & 8 deletions lua/flutter-tools/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ end
---Post a message to UI so the user knows something has occurred.
---@param msg string | string[]
---@param level integer
---@param opts {timeout: number}?
---@param opts {timeout: number, once: boolean}?
M.notify = function(msg, level, opts)
opts = opts or {}
level = level or M.INFO
opts, level = opts or {}, level or M.INFO
msg = type(msg) == "table" and utils.join(msg) or msg
if msg == "" then return end
vim.notify(msg, level, {
title = "Flutter tools",
timeout = opts.timeout,
icon = "",
})
local args = { title = "Flutter tools", timeout = opts.timeout, icon = "" }
if opts.once then
vim.notify_once(msg, level, args)
else
vim.notify(msg, level, args)
end
end

---@param opts table
Expand Down

0 comments on commit 1891476

Please sign in to comment.