Skip to content

Commit cc07c74

Browse files
committed
fix(cmdline): truncate window title using final width
1 parent 6f11e41 commit cc07c74

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

lua/mini/cmdline.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,13 @@ H.peek_get_config = function(height)
10061006
if vim.is_callable(win_config) then win_config = win_config() end
10071007
local config = vim.tbl_deep_extend('force', default_config, win_config or {})
10081008

1009-
if type(config.title) == 'string' then config.title = H.fit_to_width(config.title, config.width) end
1010-
10111009
-- Tweak config values to ensure they are proper, accounting for border
10121010
local offset = config.border == 'none' and 0 or 2
10131011
config.height = math.max(math.min(config.height, vim.o.lines - cmdheight - offset), 1)
10141012
config.width = math.min(config.width, vim.o.columns - offset)
10151013

1014+
if type(config.title) == 'string' then config.title = H.fit_to_width(config.title, config.width) end
1015+
10161016
return config
10171017
end
10181018

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--|---------|---------|
2+
01|My tabline
3+
02|Line 1
4+
03|Line 2
5+
04|Line 3
6+
05|Line 4
7+
06|┌…jklmnopqrstuvwxyz┐
8+
07|│ │Line 1 │
9+
08|│🭬2│Line 2 │
10+
09|│ │Line 3 │
11+
10|└──────────────────┘
12+
11|:2
13+
14+
--|---------|---------|
15+
01|00000000000000000000
16+
02|11111111111111111111
17+
03|11111111111111111111
18+
04|11111111111111111111
19+
05|11111111111111111111
20+
06|23333333333333333332
21+
07|24456666666666666662
22+
08|27456666666666666662
23+
09|24456666666666666662
24+
10|22222222222222222222
25+
11|88888888888888888888

tests/test_cmdline.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,14 @@ T['Autopeek']['respects `config.autopeek.window.config`'] = function()
14211421
return { border = 'double', width = 0.25 * vim.o.columns, height = 5, title = 'Custom title to check truncation' }
14221422
end]])
14231423
expect_screenshot_after_keys({ ':', '2' })
1424+
type_keys('<Esc>')
1425+
1426+
-- Should properly truncate title
1427+
child.lua([[
1428+
local title = string.sub('abcdefgijklmnopqrstuvwxyz', -vim.o.columns)
1429+
MiniCmdline.config.autopeek.window.config = { width = vim.o.columns, title = title }
1430+
]])
1431+
expect_screenshot_after_keys({ ':', '2' })
14241432
end
14251433

14261434
T['Autopeek']["respects 'winborder'"] = function()

0 commit comments

Comments
 (0)