Skip to content

Commit

Permalink
fix: timestamp zero representation caching (#836)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
christoph-heinrich authored Jan 20, 2024
1 parent 0f970b5 commit 63aba05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/uosc/lib/text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/uosc/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 63aba05

Please sign in to comment.