Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion codeminimap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion textview_minimap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions textview_minimap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading