From 763b9a0b313bf3e00fa640028228c4a4f1a01466 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Thu, 22 Oct 2026 09:45:33 +0200 Subject: [PATCH] feat: minimap ticks for search matches wear the highlight colour (MinimapMark.Color) A CodeEditor whose MatchColor is red (the go-slides playground marks its problems that way) now gets red ticks on the minimap, pulled toward OnSurface where they would sit under 3:1 on the panel. Co-Authored-By: Claude Opus 5.5 --- codeminimap.go | 11 ++++++++++- textview_minimap.go | 2 +- textview_minimap_test.go | 6 ++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/codeminimap.go b/codeminimap.go index ff87179..519cf56 100644 --- a/codeminimap.go +++ b/codeminimap.go @@ -27,6 +27,11 @@ const ( type MinimapMark struct { Line int Kind MarkKind + // Color, when its alpha is non-zero, is the tick's colour instead of the one + // Kind picks (the minimap still pulls it toward OnSurface if it would sit + // under 3:1 on the panel). A CodeEditor sets it on its search-match marks so a + // tick wears the colour the match is highlighted in. + Color RGBA } // minimapMarkColor is the tick colour for kind on a minimap whose panel is the @@ -287,7 +292,11 @@ func (m *CodeMinimap) Draw(p painter.Painter, theme *Theme) { continue } row := rowForLine(mk.Line, displayRows, n) - fillRect(p, r.X+r.W-tickW, r.Y+row*rowH, tickW, atLeast1(rowH-scaled(1)), minimapMarkColor(theme, mk.Kind)) + c := minimapMarkColor(theme, mk.Kind) + if mk.Color.A != 0 { + c = ensureContrast(RGB(mk.Color.R, mk.Color.G, mk.Color.B), theme.SurfaceAlt, theme.OnSurface, 3) + } + fillRect(p, r.X+r.W-tickW, r.Y+row*rowH, tickW, atLeast1(rowH-scaled(1)), c) } } diff --git a/textview_minimap.go b/textview_minimap.go index 0d3e152..af15c0d 100644 --- a/textview_minimap.go +++ b/textview_minimap.go @@ -83,7 +83,7 @@ func (t *TextView) drawMinimap(p painter.Painter, theme *Theme) { m := t.syncMinimap() t.mmBuf = append(t.mmBuf[:0], t.mmMarks...) for _, b := range t.matchBands { - t.mmBuf = append(t.mmBuf, MinimapMark{Line: b.sel.StartLine, Kind: MarkMatch}) + t.mmBuf = append(t.mmBuf, MinimapMark{Line: b.sel.StartLine, Kind: MarkMatch, Color: b.color}) } m.Marks = t.mmBuf m.Draw(p, theme) diff --git a/textview_minimap_test.go b/textview_minimap_test.go index 8928690..4cc5e31 100644 --- a/textview_minimap_test.go +++ b/textview_minimap_test.go @@ -139,11 +139,17 @@ func TestMinimapMarksAndMatchesDrawn(t *testing.T) { tick := func(line int) RGBA { return pixelAt(buf, 420, c.Bounds().X+rc.X+rc.W-1, c.Bounds().Y+rc.Y+line*rowH) } + // a match wears its highlight colour (the editor's MatchColor), made legible + bandC := c.matchBands[0].color + matchWant := ensureContrast(RGB(bandC.R, bandC.G, bandC.B), th.SurfaceAlt, th.OnSurface, 3) for _, k := range []struct { line int kind MarkKind }{{10, MarkError}, {20, MarkWarning}, {30, MarkMatch}} { want := minimapMarkColor(th, k.kind) + if k.kind == MarkMatch { + want = matchWant + } if got := tick(k.line); got != want { t.Errorf("%s: tick for line %d = %v, want %v", name, k.line, got, want) }