Skip to content

Commit ce1e5c7

Browse files
committed
Improve handling of line padding in vertical cursor motion
FIX: Fix an issue where `moveVertially` was sometimes unable to escape lines with thick borders or padding.
1 parent 6455bc9 commit ce1e5c7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/cursor.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,18 @@ export function posAtCoords(view: EditorView, coords: {x: number, y: number}, pr
183183
let content = view.contentDOM.getBoundingClientRect(), docTop = content.top + view.viewState.paddingTop
184184
let {x, y} = coords, yOffset = y - docTop, block
185185
// First find the block at the given Y position, if any. If scanY is
186-
// given (used for vertical cursor motion), try to skip widgets.
186+
// given (used for vertical cursor motion), try to skip widgets and
187+
// line padding.
187188
for (;;) {
188189
if (yOffset < 0) return new PosAssoc(0, 1)
189190
if (yOffset > view.viewState.docHeight) return new PosAssoc(view.state.doc.length, -1)
190191
block = view.elementAtHeight(yOffset)
191-
if (scanY == null || block.type == BlockType.Text) break
192+
if (scanY == null) break
193+
if (block.type == BlockType.Text) {
194+
// Check whether we aren't landing the top/bottom padding of the line
195+
let rect = view.docView.coordsAt(scanY < 0 ? block.from : block.to, scanY)
196+
if (rect && (scanY < 0 ? rect.top <= yOffset + docTop : rect.bottom >= yOffset + docTop)) break
197+
}
192198
let halfLine = view.viewState.heightOracle.textHeight / 2
193199
yOffset = scanY > 0 ? block.bottom + halfLine : block.top - halfLine
194200
}

0 commit comments

Comments
 (0)