fix: timestamp offsets should respect the trimmed time width (#443)

* fix: constant width for hovered time

* fix: respect the trimmed time width in the buffered time indicator

* perf: cache timestamp substitutes for width calculation

Co-authored-by: tomasklaen <tomas.klaen@gmail.com>

---------

Co-authored-by: tomasklaen <tomas.klaen@gmail.com>
This commit is contained in:
christoph-heinrich
2023-01-31 09:11:56 +01:00
committed by GitHub
parent e3c06eb814
commit 811b2c5f33
2 changed files with 21 additions and 4 deletions

View File

@@ -368,6 +368,24 @@ do
end
end
do
---@type {[string]: string}
local cache = {}
---Get width of formatted timestamp as if all the digits were replaced with 0
---@param timestamp string
---@param opts {size: number; bold?: boolean; italic?: boolean}
---@return number
function timestamp_width(timestamp, opts)
local substitute = cache[#timestamp]
if not substitute then
substitute = timestamp:gsub('%d', '0')
cache[#timestamp] = substitute
end
return text_width(substitute, opts)
end
end
---Wrap the text at the closest opportunity to target_line_length
---@param text string
---@param opts {size: number; bold?: boolean; italic?: boolean}