Skip to content

Commit 5cdd276

Browse files
committed
fix: #1440
1 parent 6a8dbf0 commit 5cdd276

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lua/gitsigns/highlight.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ do --- temperature highlight
330330
function M.get_temp_hl(min, max, t, alpha, fg)
331331
local Color = require('gitsigns.color')
332332

333-
local normalized_t = (t - min) / (math.max(max, t) - min)
333+
local denom = math.max(max, t) - min
334+
local normalized_t = denom ~= 0 and (t - min) / denom or 0
334335
local raw_temp_color = Color.temp(normalized_t)
335336

336337
if normal_bg == nil then

test/highlights_spec.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ local expectf = helpers.expectf
1010
local match_dag = helpers.match_dag
1111
local p = helpers.p
1212
local setup_gitsigns = helpers.setup_gitsigns
13+
local eq = helpers.eq
1314

1415
helpers.env()
1516

@@ -82,4 +83,21 @@ describe('highlights', function()
8283
config.linehl = true
8384
setup_gitsigns(config)
8485
end)
86+
87+
it('get_temp_hl handles equal min/max', function()
88+
helpers.setup_path()
89+
local res = helpers.exec_lua(function()
90+
vim.api.nvim_set_hl(0, 'Normal', { bg = 0x000000 })
91+
92+
package.loaded['gitsigns.highlight'] = nil
93+
local hl = require('gitsigns.highlight')
94+
95+
local name = hl.get_temp_hl(0, 0, 0, 0.5, true)
96+
local info = vim.api.nvim_get_hl(0, { name = name, link = false })
97+
return { name = name, fg = info.fg }
98+
end)
99+
100+
assert(res.name:match('^GitSignsColorTemp%.fg%.%d+$') ~= nil)
101+
eq(0x00007F, res.fg)
102+
end)
85103
end)

0 commit comments

Comments
 (0)