Skip to content

Commit

Permalink
Remove extra vertical margins around selection rectangles
Browse files Browse the repository at this point in the history
FIX: Make selection rectangles verticaly align precisely, rather than introducing
a slight overlap.

See https://discuss.codemirror.net/t/issue-with-selection-highlight-overlapping/8882
  • Loading branch information
marijnh committed Dec 10, 2024
1 parent 6e6b285 commit 6d3f7ad
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ function wrappedLine(view: EditorView, pos: number, side: 1 | -1, inside: {from:
return {from: Math.max(inside.from, Math.min(left, right)), to: Math.min(inside.to, Math.max(left, right))}
}

// Added to range rectangle's vertical extent to prevent rounding
// errors from introducing gaps in the rendered content.
const enum C { Epsilon = 0.01 }

function rectanglesForRange(view: EditorView, className: string, range: SelectionRange): RectangleMarker[] {
if (range.to <= view.viewport.from || range.from >= view.viewport.to) return []
let from = Math.max(range.from, view.viewport.from), to = Math.min(range.to, view.viewport.to)
Expand Down Expand Up @@ -135,8 +131,8 @@ function rectanglesForRange(view: EditorView, className: string, range: Selectio
}

function piece(left: number, top: number, right: number, bottom: number) {
return new RectangleMarker(className, left - base.left, top - base.top - C.Epsilon,
right - left, bottom - top + C.Epsilon)
return new RectangleMarker(className, left - base.left, top - base.top,
right - left, bottom - top)
}
function pieces({top, bottom, horizontal}: {top: number, bottom: number, horizontal: number[]}) {
let pieces = []
Expand Down

0 comments on commit 6d3f7ad

Please sign in to comment.