Skip to content

fix(markdown): widen within cell on empty code lines in offsetAtIndexed and add linear equivalence tests - #73

Merged
Mucheen merged 1 commit into
mainfrom
fix/markdown-index-empty-code-line
Nov 28, 2026
Merged

Mucheen merged 1 commit into
mainfrom
fix/markdown-index-empty-code-line

Conversation

@Mucheen

@Mucheen Mucheen commented Nov 28, 2026

Copy link
Copy Markdown

Summary

Fixes the empty-code-line hit-test regression caught during upstream review on vivaui#489:

  1. components/markdown_index.go (offsetAtIndexed):
    • Widen outward within the current cell/block (checkRowsNearY) and within table rows by increasing vertical distance, pruning only when minDy * 1_000_000 > bestScore.
    • Preserve exact reading-order tie-breaking (pi < best) and cross-cell same-line gap interpolation (prevPlainPiece), making offsetAtIndexed bit-for-bit equivalent to the pre-index linear scan on every (x, y), including blank lines inside code blocks.
    • Clarify AllocatedBytes doc comment to describe what the method reports without host-product framing.
  2. components/markdown_index_test.go:
    • Add TestMarkdownIndexMatchesLinearReferenceOnGrid comparing OffsetAt (dense (x, y) grid) and CaretAt (every byte offset 0..TextLen()) against linear reference implementations on Parse-built documents (empty code lines, horizontal rules, tables with empty/wrapped cells, nested quotes, lists, UTF-8) and programmatic Labeled documents.
    • Add TestMarkdownEmptyCodeLinesStayInCodeBlock direct regression test.
    • Remove direct reads of unexported blockSpans / cellSpans from TestMarkdownBuilderLabeledAndOpaqueLinks.
  3. cmd/viva/templates/:

Verification

  • gofmt & go vet ./...
  • go test ./markdown/... ./components/... ./tools/docs/... -count=1
  • go test ./cmd/viva -run 'TestListCoversEveryReferenceComponent|TestGeneratedRecipesAreCurrent|TestInstalledRecipesMatchReferenceSource' -count=1
  • BenchmarkMarkdownViewClippedPaintSteady: 1580 ns/op, 0 B/op, 0 allocs/op
  • GOOS=windows GOARCH=amd64/arm64 go build ./... and GOOS=js GOARCH=wasm go build ./markdown/... ./components/...

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