fix: timestamp zero representation caching (#836)

Caching the zero represenation sounds like a good idea, until the
precision gets changed and then e.g. 01:40:23.13 returns -00:00:00.0
because it has the same amount of characters, messing up our width
estimation and pseudo monospace thingy.

Clearing the cache on options change avoids such conflicts.

Fixes #834
This commit is contained in:
christoph-heinrich
2024-01-20 21:26:07 +01:00
committed by GitHub
parent 0f970b5d8e
commit 63aba054ea
2 changed files with 8 additions and 1 deletions

View File

@@ -408,6 +408,10 @@ do
---@type {[string]: string}
local cache = {}
function timestamp_zero_rep_clear_cache()
cache = {}
end
---Replace all timestamp digits with 0
---@param timestamp string
function timestamp_zero_rep(timestamp)

View File

@@ -102,7 +102,10 @@ defaults = {
disable_elements = '',
}
options = table_copy(defaults)
opt.read_options(options, 'uosc', function(_)
opt.read_options(options, 'uosc', function(changed_options)
if changed_options.time_precision then
timestamp_zero_rep_clear_cache()
end
update_config()
update_human_times()
Manager:disable('user', options.disable_elements)