Skip to content

Commit

Permalink
fix(wrapped-compact): avoid mutating message
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Jan 3, 2024
1 parent ebcdd82 commit 1576123
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
10 changes: 8 additions & 2 deletions doc/nvim-notify.txt
Expand Up @@ -33,6 +33,10 @@ Default values:
minimum_width = 50,
render = "default",
stages = "fade_in_slide_out",
time_formats = {
notification = "%T",
notification_history = "%FT%T"
},
timeout = 5000,
top_down = true
}
Expand Down Expand Up @@ -115,7 +119,7 @@ Get records of all previous notifications

You can use the `:Notifications` command to display a log of previous notifications
Parameters~
{opts} `(notify.HistoryOpts)`
{opts?} `(notify.HistoryOpts)`
Return~
`(notify.Record[])`

Expand Down Expand Up @@ -187,6 +191,7 @@ Fields~
{stages} `(string|function[])` Animation stages
{background_colour} `(string)` For stages that change opacity this is treated as the highlight behind the window. Set this to either a highlight group, an RGB hex value e.g. "#000000" or a function returning an RGB code for dynamic values
{icons} `(table)` Icons for each level (upper case names)
{time_formats} `(table)` Time formats for different kind of notifications
{on_open} `(function)` Function called when a new window is opened, use for changing win settings/config
{on_close} `(function)` Function called when a window is closed
{render} `(function|string)` Function to render a notification buffer or a built-in renderer name
Expand All @@ -208,6 +213,7 @@ Built-in renderers:
- `"default"`
- `"minimal"`
- `"simple"`
- `"compact"`
- `"wrapped-compact"`

Custom functions should accept a buffer, a notification record and a highlights table
Expand All @@ -226,4 +232,4 @@ Fields~
{body} `(string)`


vim:tw=78:ts=8:noet:ft=help:norl:
vim:tw=78:ts=8:noet:ft=help:norl:
2 changes: 1 addition & 1 deletion lua/notify/init.lua
Expand Up @@ -98,7 +98,7 @@ end
--- Get records of all previous notifications
---
--- You can use the `:Notifications` command to display a log of previous notifications
---@param opts notify.HistoryOpts
---@param opts? notify.HistoryOpts
---@return notify.Record[]
function notify.history(opts)
if not global_instance then
Expand Down
2 changes: 2 additions & 0 deletions lua/notify/render/init.lua
Expand Up @@ -10,6 +10,8 @@
--- - `"default"`
--- - `"minimal"`
--- - `"simple"`
--- - `"compact"`
--- - `"wrapped-compact"`
---
--- Custom functions should accept a buffer, a notification record and a highlights table
---
Expand Down
10 changes: 5 additions & 5 deletions lua/notify/render/wrapped-compact.lua
Expand Up @@ -49,7 +49,7 @@ return function(bufnr, notif, highlights, config)
if max_width == nil then
max_width = 80
end
notif.message = custom_wrap(notif.message, max_width)
local message = custom_wrap(notif.message, max_width)

local default_titles = { "Error", "Warning", "Notify" }
local has_valid_manual_title = type(title) == "string"
Expand All @@ -59,14 +59,14 @@ return function(bufnr, notif, highlights, config)
if has_valid_manual_title then
-- has title = icon + title as header row
prefix = string.format(" %s %s", icon, title)
table.insert(notif.message, 1, prefix)
table.insert(message, 1, prefix)
else
-- no title = prefix the icon
prefix = string.format(" %s", icon)
notif.message[1] = string.format("%s %s", prefix, notif.message[1])
message[1] = string.format("%s %s", prefix, message[1])
end

vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, notif.message)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, message)

local icon_length = vim.str_utfindex(icon)
local prefix_length = vim.str_utfindex(prefix) + 1
Expand All @@ -83,7 +83,7 @@ return function(bufnr, notif, highlights, config)
})
vim.api.nvim_buf_set_extmark(bufnr, namespace, 0, prefix_length + 1, {
hl_group = highlights.body,
end_line = #notif.message,
end_line = #message,
priority = 50,
})
end

0 comments on commit 1576123

Please sign in to comment.