Skip to content

Commit 121d830

Browse files
committed
fix(notify): truncate window title using final width
1 parent 47786a3 commit 121d830

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

lua/mini/notify.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,12 +815,11 @@ H.window_compute_config = function(buf_id, is_for_open)
815815
if vim.is_callable(win_config) then win_config = win_config(buf_id) end
816816
local config = vim.tbl_deep_extend('force', default_config, win_config or {})
817817

818-
if type(config.title) == 'string' then config.title = H.fit_to_width(config.title, config.width) end
819-
820818
-- Tweak config values to ensure they are proper, accounting for border
821819
local offset = config.border == 'none' and 0 or 2
822820
config.height = math.min(config.height, max_height - offset)
823821
config.width = math.min(config.width, max_width - offset)
822+
if type(config.title) == 'string' then config.title = H.fit_to_width(config.title, config.width) end
824823

825824
return config
826825
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--|---------|---------|---------|---------|-----
2+
01|┌…jklmnopqrstuvwxyzabcdefgijklmnopqrstuvwxyz┐
3+
02|│12:34:57 │ World │
4+
03|│12:34:56 │ Hello │
5+
04|└───────────────────────────────────────────┘
6+
05|~
7+
06|~
8+
07|~
9+
08|~
10+
09|~
11+
10|~
12+
11|~
13+
12| 0,0-1 All
14+
15+
--|---------|---------|---------|---------|-----
16+
01|011111111111111111111111111111111111111111110
17+
02|022222222222222222222222222222222222222222220
18+
03|022222222222222222222222222222222222222222220
19+
04|000000000000000000000000000000000000000000000
20+
05|333333333333333333333333333333333333333333333
21+
06|333333333333333333333333333333333333333333333
22+
07|333333333333333333333333333333333333333333333
23+
08|333333333333333333333333333333333333333333333
24+
09|333333333333333333333333333333333333333333333
25+
10|333333333333333333333333333333333333333333333
26+
11|333333333333333333333333333333333333333333333
27+
12|444444444444444444444444444444444444444444444

tests/test_notify.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,23 @@ T['Window']['respects `window.config`'] = function()
830830
add('World')
831831
child.expect_screenshot()
832832

833+
if child.fn.has('nvim-0.10') == 0 then MiniTest.skip('Neovim<0.10 has issues with displaying title in some cases') end
834+
833835
-- As callable
834836
child.lua([[MiniNotify.config.window.config = function(buf_id)
835837
_G.buffer_filetype = vim.bo[buf_id].filetype
836838
return { border = 'double', width = 25, height = 5, title = 'Custom title to check truncation' }
837839
end]])
838840
refresh()
839-
-- NOTE: Neovim<0.10 has issues with displaying title in this case
840-
if child.fn.has('nvim-0.10') == 1 then child.expect_screenshot() end
841+
child.expect_screenshot()
842+
843+
-- Should properly truncate title
844+
child.lua([[
845+
local title = string.sub('abcdefgijklmnopqrstuvwxyzabcdefgijklmnopqrstuvwxyz', -vim.o.columns)
846+
MiniNotify.config.window.config = { width = vim.o.columns, title = title }
847+
]])
848+
refresh()
849+
child.expect_screenshot()
841850
end
842851

843852
T['Window']["respects 'winborder' option"] = function()

0 commit comments

Comments
 (0)