@@ -143,6 +143,68 @@ local add_drafts_and_resolvable = function(
143143 return base_title
144144end
145145
146+ -- Returns true if the input string (after removing highlighting and alignment strings) is wider
147+ -- than the discussion split.
148+ --- @return boolean
149+ local too_long = function (str )
150+ local d = require (" gitlab.actions.discussions" )
151+ return # str :gsub (" %%#[^#]+#" , " " ):gsub (" %%= " , " " ) > vim .fn .winwidth (d .split .winid )
152+ end
153+
154+ -- Returns the input winbar string shortened to fit into the windo width.
155+ --- @return string
156+ local adapt_to_winwidth = function (str )
157+ if too_long (str ) then
158+ str = str :gsub (" Inline " , " " )
159+ end
160+ if too_long (str ) then
161+ str = str :gsub (" by thread" , " thread" )
162+ str = str :gsub (" by reply" , " reply" )
163+ end
164+ if too_long (str ) then
165+ str = str :gsub (" Mode" , " " )
166+ end
167+ if too_long (str ) then
168+ str = str :gsub (" Help" , " H" )
169+ end
170+ if too_long (str ) then
171+ str = str :gsub (" just now" , " now" )
172+ str = str :gsub (" (%d+) minutes?" , " %1m" )
173+ str = str :gsub (" (%d+) hours?" , " %1h" )
174+ str = str :gsub (" (%d+) days?" , " %1d" )
175+ end
176+ if too_long (str ) then
177+ str = str :gsub (" ↓ thread" , " ↓" )
178+ str = str :gsub (" ↑ reply" , " ↑" )
179+ end
180+ if too_long (str ) then
181+ str = str :gsub (" Updated" , " U" )
182+ end
183+ if too_long (str ) then
184+ str = str :gsub (" Draft" , " D" )
185+ str = str :gsub (" Live" , " L" )
186+ end
187+ if too_long (str ) then
188+ str = str :gsub (" (%d+) comments?" , " %1c" )
189+ end
190+ if too_long (str ) then
191+ str = str :gsub (" (%d+/%d+) threads?" , " %1t" )
192+ end
193+ if too_long (str ) then
194+ str = str :gsub (" (%d+) drafts?" , " %1d" )
195+ end
196+ if too_long (str ) then
197+ str = str :gsub (" (%d+%a) ago" , " %1" )
198+ end
199+ if too_long (str ) then
200+ str = str :gsub (" Comments" , " C" )
201+ end
202+ if too_long (str ) then
203+ str = str :gsub (" Notes" , " N" )
204+ end
205+ return str
206+ end
207+
146208--- @param t WinbarTable
147209M .make_winbar = function (t )
148210 local discussion_title = add_drafts_and_resolvable (
@@ -176,7 +238,7 @@ M.make_winbar = function(t)
176238 local separator = " %#Comment#|"
177239 local end_section = " %="
178240 local help = " %#Comment#Help: " .. (t .help_keymap and t .help_keymap :gsub (" " , " <space>" ) .. " " or " unmapped" )
179- return string.format (
241+ local result = string.format (
180242 " %s %s %s %s %s %s %s %s %s" ,
181243 discussion_title ,
182244 separator ,
@@ -188,6 +250,7 @@ M.make_winbar = function(t)
188250 separator ,
189251 help
190252 )
253+ return adapt_to_winwidth (result )
191254end
192255
193256--- Returns a string for the winbar indicating the sort method
0 commit comments