Skip to content

feat(marks): add highlight_from to show the color of the covered mark - #135

Merged
petertriho merged 1 commit into
mainfrom
feat/highlight-from-covered
Nov 21, 2026
Merged

petertriho merged 1 commit into
mainfrom
feat/highlight-from-covered

Conversation

@petertriho

Copy link
Copy Markdown
Owner

Adds highlight_from to the mark types, so that a scrollbar mark can show in the color of the mark that it covers. The main use is the cursor: with the option, the cursor dot on a row with an Error shows in the Error color. The default "self" keeps the current behavior.

Changes

  • highlight_from: each mark type accepts "self" (the default) or "covered". The top-level marks, scrollbar.marks, presets, and profiles accept the key. A renderer override or a profile turns off a shared "covered" with "self".
  • Covered marks: a mark covers the marks that the cell would show without it. These are the marks of its lane that lose the collision to it, and the marks of lower mark layers in the same cells. The cell takes the first covered mark in that order: its own lane by priority, then the lower layers from the top down. A mark in another column of the same row does not count.
  • Chains: a covered mark that also sets highlight_from = "covered" does not count. When no covered mark counts, the mark keeps its own highlight.
  • Groups: the cell uses the groups of the covered type: Scrollbar<Type>, Scrollbar<Type>Thumb, Scrollbar<Type>ThumbPressed, Scrollbar<Type>Tint, and their inactive groups. The option adds no groups. The inactive_highlight of the covering mark applies only when it covers no mark.
  • Scope: only the color changes. The hit data, the hover, the peek float, and the jump labels still use the type of the mark, for example Cursor. The minimap ignores the option, and minimap.marks rejects it.
  • Docs: docs/configuration.md (Marks), docs/highlights.md (new Covered Marks section), and docs/minimap/README.md.
require("scrollbar").setup({
    marks = {
        Cursor = { highlight_from = "covered" },
    },
})

Review Notes

  • Lane collisions: place_marks and place_row record the first dropped non-inheriting type on the inheriting glyph that drops it (covered_type). A dropped glyph counts only when that one glyph takes all of its taken cells. The two functions have the same body, so both have the change.
  • Row reuse: a dropped glyph leaves no placed object, so row_equivalent now compares covered_type. Without that comparison, the compose reused a stale row after the covered mark moved away. The compose test and both renderer tests fail without it.
  • Stacked layers: collect_row_marks resolves an inheriting winner without a covered_type from the lower layers. The result stays in a table of the row, not on the placed marks, because the compose reuses the placed marks of a row.
  • Cache key: layout_config copies highlight_from, so two profiles that differ only in the option do not share a mark layer.
  • Cost when unused: without the option, a render does only a few extra field checks, and the stack pass does not run. make bench-compare REF=main reports 0 regressions. render/line/cursor_mark is 40.4 µs on main and 43.8 µs on the branch, which the tool rates as noise. The new case render/line/cursor_mark_covered (the cursor over a mark on most rows) takes 42.2 µs.
  • Benchmark report: in the comparison, the base side of cursor_mark_covered errors, because main rejects the new key. The next case, thumb_text_scroll, then also errors on the base side, because the failed setup skips its teardown. Both cases run on the branch.
  • Defaults to confirm: a glyph wider than one cell takes one color, the first mark that it covers. Setup stores "self" as nil, so the default specs and cache keys do not change.
  • Tint mode: with overlap.marks = "tint", a covering cell takes the tint of the covered mark, so it looks the same as that mark. This is intentional and documented.

Tests

  • make ci passes: format, lint, typecheck, and the full suite on Neovim 0.12.6 (1230 cases).
  • tests/test_compositor.lua: lane collisions, priority among covered marks, no covered mark, chains, lower layers and lane-first order, a lower mark that the thumb hides, thumb and tint groups, a wide glyph, the covered type in full and incremental layers, and the row reuse case.
  • tests/test_renderer.lua: the cursor moves onto and off an Error row through the in-place path, and a diagnostic appears on the cursor row. A randomized test compares incremental renders with full renders over 200 steps.
  • tests/test_inactive.lua: an inactive window uses the inactive group of the covered type, not the inactive group of the cursor.
  • tests/config/test_init.lua and tests/config/test_profiles.lua: validation, the renderer override, the minimap rejection, the profile, and the layout cache key.

A scrollbar mark type with `highlight_from = "covered"` now shows in the
highlight of the mark that it covers in its cell. With
`marks.Cursor = { highlight_from = "covered" }`, the cursor dot on a row
with an Error shows in the Error color. The default `"self"` keeps the
current behavior. The renderer overrides, presets, and profiles accept
the key. The minimap ignores it, and `minimap.marks` rejects it.

A mark covers the marks that the cell would show without it: the marks
of its lane that lose the collision, and the marks of lower mark layers
in the same cells. The cell takes the first covered mark in that order.
A covered mark that also inherits does not count. Without a covered
mark, the mark keeps its own highlight. Only the color changes. The hit
data, the hover, the peek float, and the jump labels still use the type
of the mark.

The cell uses the groups of the covered type, so the thumb, tint,
pressed, and inactive variants work without new groups. The layer stage
records the covered type of a lane collision on the placed glyph, and
the row reuse of the compose compares it. The field is in the layout
cache key. Without the option, a render does only a few extra field
checks.

The new case `render/line/cursor_mark_covered` takes 42 us, against
38 us for `cursor_mark_search`. `make bench-compare REF=main` reports 0
regressions.
@petertriho
petertriho merged commit 38e3bda into main Nov 21, 2026
6 checks passed
@petertriho
petertriho deleted the feat/highlight-from-covered branch November 21, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant