Skip to content
Snippets Groups Projects
Commit 8e860c53 authored by Adrian Heine's avatar Adrian Heine
Browse files

Make calculateScrollPos private, introduce scrollToCoordsRange

parent 4c3fa246
No related branches found
No related tags found
No related merge requests found
......@@ -69,7 +69,7 @@ export function scrollIntoView(cm, rect) {
// rectangle into view. Returns an object with scrollTop and
// scrollLeft properties. When these are undefined, the
// vertical/horizontal position does not need to be adjusted.
export function calculateScrollPos(cm, rect) {
function calculateScrollPos(cm, rect) {
let display = cm.display, snapMargin = textHeight(cm.display)
if (rect.top < 0) rect.top = 0
let screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop
......@@ -128,15 +128,20 @@ export function resolveScrollToPos(cm) {
if (range) {
cm.curOp.scrollToPos = null
let from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to)
let sPos = calculateScrollPos(cm, {
left: Math.min(from.left, to.left),
top: Math.min(from.top, to.top) - range.margin,
right: Math.max(from.right, to.right),
bottom: Math.max(from.bottom, to.bottom) + range.margin
})
cm.scrollTo(sPos.scrollLeft, sPos.scrollTop)
scrollToCoordsRange(cm, from, to, range.margin)
}
}
export function scrollToCoordsRange(cm, from, to, margin) {
let sPos = calculateScrollPos(cm, {
left: Math.min(from.left, to.left),
top: Math.min(from.top, to.top) - margin,
right: Math.max(from.right, to.right),
bottom: Math.max(from.bottom, to.bottom) + margin
})
cm.scrollTo(sPos.scrollLeft, sPos.scrollTop)
}
// Sync the scrollable area and scrollbars, ensure the viewport
// covers the visible area.
export function updateScrollTop(cm, val) {
......
......@@ -14,7 +14,7 @@ import { clipLine, clipPos, equalCursorPos, Pos } from "../line/pos"
import { charCoords, charWidth, clearCaches, clearLineMeasurementCache, coordsChar, cursorCoords, displayHeight, displayWidth, estimateLineHeights, fromCoordSystem, intoCoordSystem, scrollGap, textHeight } from "../measurement/position_measurement"
import { Range } from "../model/selection"
import { replaceOneSelection, skipAtomic } from "../model/selection_updates"
import { addToScrollPos, calculateScrollPos, ensureCursorVisible, resolveScrollToPos, scrollIntoView } from "../display/scrolling"
import { addToScrollPos, ensureCursorVisible, resolveScrollToPos, scrollIntoView, scrollToCoordsRange } from "../display/scrolling"
import { heightAtLine } from "../line/spans"
import { updateGutterSpace } from "../display/update_display"
import { indexOf, insertSorted, isWordChar, sel_dontScroll, sel_move } from "../util/misc"
......@@ -388,13 +388,7 @@ export default function(CodeMirror) {
resolveScrollToPos(this)
this.curOp.scrollToPos = range
} else {
let sPos = calculateScrollPos(this, {
left: Math.min(range.from.left, range.to.left),
top: Math.min(range.from.top, range.to.top) - range.margin,
right: Math.max(range.from.right, range.to.right),
bottom: Math.max(range.from.bottom, range.to.bottom) + range.margin
})
this.scrollTo(sPos.scrollLeft, sPos.scrollTop)
scrollToCoordsRange(this, range.from, range.to, range.margin)
}
}),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment