Skip to content

Commit

Permalink
Clip scroll margins to reasonable values
Browse files Browse the repository at this point in the history
FIX: Fix an issue where passing large scroll margins to `scrollIntoView` would
cause the measure loop to fail to terminate.
  • Loading branch information
marijnh committed Nov 2, 2023
1 parent 5dfda8e commit a151d42
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/docview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,11 @@ export class DocView extends ContentView {
left: rect.left - margins.left, top: rect.top - margins.top,
right: rect.right + margins.right, bottom: rect.bottom + margins.bottom
}
let sDOM = this.view.scrollDOM
scrollRectIntoView(this.view.scrollDOM, targetRect, range.head < range.anchor ? -1 : 1,
target.x, target.y, target.xMargin, target.yMargin,
target.x, target.y,
Math.max(0, Math.min(target.xMargin, sDOM.offsetWidth)),
Math.max(0, Math.min(target.yMargin, sDOM.offsetHeight)),
this.view.textDirection == Direction.LTR)
}

Expand Down
4 changes: 3 additions & 1 deletion src/editorview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,11 @@ export class EditorView {
x?: ScrollStrategy,
/// Extra vertical distance to add when moving something into
/// view. Not used with the `"center"` strategy. Defaults to 5.
/// Must be less than the height of the editor.
yMargin?: number,
/// Extra horizontal distance to add. Not used with the `"center"`
/// strategy. Defaults to 5.
/// strategy. Defaults to 5. Must be less than the width of the
/// editor.
xMargin?: number,
} = {}): StateEffect<unknown> {
return scrollIntoView.of(new ScrollTarget(typeof pos == "number" ? EditorSelection.cursor(pos) : pos,
Expand Down

0 comments on commit a151d42

Please sign in to comment.