Skip to content

Commit 1576123

Browse files
committed
fix(wrapped-compact): avoid mutating message
1 parent ebcdd82 commit 1576123

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

doc/nvim-notify.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Default values:
3333
minimum_width = 50,
3434
render = "default",
3535
stages = "fade_in_slide_out",
36+
time_formats = {
37+
notification = "%T",
38+
notification_history = "%FT%T"
39+
},
3640
timeout = 5000,
3741
top_down = true
3842
}
@@ -115,7 +119,7 @@ Get records of all previous notifications
115119

116120
You can use the `:Notifications` command to display a log of previous notifications
117121
Parameters~
118-
{opts} `(notify.HistoryOpts)`
122+
{opts?} `(notify.HistoryOpts)`
119123
Return~
120124
`(notify.Record[])`
121125

@@ -187,6 +191,7 @@ Fields~
187191
{stages} `(string|function[])` Animation stages
188192
{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
189193
{icons} `(table)` Icons for each level (upper case names)
194+
{time_formats} `(table)` Time formats for different kind of notifications
190195
{on_open} `(function)` Function called when a new window is opened, use for changing win settings/config
191196
{on_close} `(function)` Function called when a window is closed
192197
{render} `(function|string)` Function to render a notification buffer or a built-in renderer name
@@ -208,6 +213,7 @@ Built-in renderers:
208213
- `"default"`
209214
- `"minimal"`
210215
- `"simple"`
216+
- `"compact"`
211217
- `"wrapped-compact"`
212218

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

228234

229-
vim:tw=78:ts=8:noet:ft=help:norl:
235+
vim:tw=78:ts=8:noet:ft=help:norl:

lua/notify/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ end
9898
--- Get records of all previous notifications
9999
---
100100
--- You can use the `:Notifications` command to display a log of previous notifications
101-
---@param opts notify.HistoryOpts
101+
---@param opts? notify.HistoryOpts
102102
---@return notify.Record[]
103103
function notify.history(opts)
104104
if not global_instance then

lua/notify/render/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
--- - `"default"`
1111
--- - `"minimal"`
1212
--- - `"simple"`
13+
--- - `"compact"`
14+
--- - `"wrapped-compact"`
1315
---
1416
--- Custom functions should accept a buffer, a notification record and a highlights table
1517
---

lua/notify/render/wrapped-compact.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ return function(bufnr, notif, highlights, config)
4949
if max_width == nil then
5050
max_width = 80
5151
end
52-
notif.message = custom_wrap(notif.message, max_width)
52+
local message = custom_wrap(notif.message, max_width)
5353

5454
local default_titles = { "Error", "Warning", "Notify" }
5555
local has_valid_manual_title = type(title) == "string"
@@ -59,14 +59,14 @@ return function(bufnr, notif, highlights, config)
5959
if has_valid_manual_title then
6060
-- has title = icon + title as header row
6161
prefix = string.format(" %s %s", icon, title)
62-
table.insert(notif.message, 1, prefix)
62+
table.insert(message, 1, prefix)
6363
else
6464
-- no title = prefix the icon
6565
prefix = string.format(" %s", icon)
66-
notif.message[1] = string.format("%s %s", prefix, notif.message[1])
66+
message[1] = string.format("%s %s", prefix, message[1])
6767
end
6868

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

7171
local icon_length = vim.str_utfindex(icon)
7272
local prefix_length = vim.str_utfindex(prefix) + 1
@@ -83,7 +83,7 @@ return function(bufnr, notif, highlights, config)
8383
})
8484
vim.api.nvim_buf_set_extmark(bufnr, namespace, 0, prefix_length + 1, {
8585
hl_group = highlights.body,
86-
end_line = #notif.message,
86+
end_line = #message,
8787
priority = 50,
8888
})
8989
end

0 commit comments

Comments
 (0)