Skip to content

Commit

Permalink
Make sure selection padding is read from an actual line element
Browse files Browse the repository at this point in the history
FIX: Fix an issue in `drawSelection` where the selection extended into the editor's padding.

Closes codemirror/dev#1096
  • Loading branch information
marijnh committed Feb 28, 2023
1 parent 08e6e72 commit c89711b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ function rectanglesForRange(view: EditorView, className: string, range: Selectio

let ltr = view.textDirection == Direction.LTR
let content = view.contentDOM, contentRect = content.getBoundingClientRect(), base = getBase(view)
let lineStyle = window.getComputedStyle(content.firstChild as HTMLElement)
let leftSide = contentRect.left + parseInt(lineStyle.paddingLeft) + Math.min(0, parseInt(lineStyle.textIndent))
let rightSide = contentRect.right - parseInt(lineStyle.paddingRight)
let lineElt = content.querySelector(".cm-line"), lineStyle = lineElt && window.getComputedStyle(lineElt)
let leftSide = contentRect.left +
(lineStyle ? parseInt(lineStyle.paddingLeft) + Math.min(0, parseInt(lineStyle.textIndent)) : 0)
let rightSide = contentRect.right - (lineStyle ? parseInt(lineStyle.paddingRight) : 0)

let startBlock = blockAt(view, from), endBlock = blockAt(view, to)
let visualStart: {from: number, to: number} | null = startBlock.type == BlockType.Text ? startBlock : null
Expand Down

0 comments on commit c89711b

Please sign in to comment.