diff --git a/src/display/scrolling.js b/src/display/scrolling.js index 9a84b7a996df71bfc62526ae98ef2ec5f8eac441..37a1a6691ee668cc97008abafba30d815dcdaed3 100644 --- a/src/display/scrolling.js +++ b/src/display/scrolling.js @@ -99,12 +99,10 @@ function calculateScrollPos(cm, rect) { // Store a relative adjustment to the scroll position in the current // operation (to be applied when the operation finishes). -export function addToScrollPos(cm, left, top) { - if (left != null || top != null) resolveScrollToPos(cm) - if (left != null) - cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left - if (top != null) - cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top +export function addToScrollTop(cm, top) { + if (top == null) return + resolveScrollToPos(cm) + cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top } // Make sure that at the end of the operation the current cursor is diff --git a/src/edit/methods.js b/src/edit/methods.js index 5262c4f9c564a91248ee94f3edaa60fe27e1c69a..8546e075e5e5c5c8e901047d7c0d1c10052428ba 100644 --- a/src/edit/methods.js +++ b/src/edit/methods.js @@ -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, ensureCursorVisible, resolveScrollToPos, scrollIntoView, scrollToCoordsRange } from "../display/scrolling" +import { addToScrollTop, 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" @@ -322,7 +322,7 @@ export default function(CodeMirror) { goals.push(headPos.left) let pos = findPosV(this, headPos, dir, unit) if (unit == "page" && range == doc.sel.primary()) - addToScrollPos(this, null, charCoords(this, pos, "div").top - headPos.top) + addToScrollTop(this, charCoords(this, pos, "div").top - headPos.top) return pos }, sel_move) if (goals.length) for (let i = 0; i < doc.sel.ranges.length; i++) diff --git a/src/model/line_widget.js b/src/model/line_widget.js index 8347066d380a4c7e66696b4e85a8ea1668bacb31..a11f9c274297485dfc5aac487c01c4c880b28c98 100644 --- a/src/model/line_widget.js +++ b/src/model/line_widget.js @@ -1,5 +1,5 @@ import { runInOp } from "../display/operations" -import { addToScrollPos } from "../display/scrolling" +import { addToScrollTop } from "../display/scrolling" import { regLineChange } from "../display/view_tracking" import { heightAtLine, lineIsHidden } from "../line/spans" import { lineNo, updateLineHeight } from "../line/utils_line" @@ -53,7 +53,7 @@ eventMixin(LineWidget) function adjustScrollWhenAboveVisible(cm, line, diff) { if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop)) - addToScrollPos(cm, null, diff) + addToScrollTop(cm, diff) } export function addLineWidget(doc, handle, node, options) { @@ -68,7 +68,7 @@ export function addLineWidget(doc, handle, node, options) { if (cm && !lineIsHidden(doc, line)) { let aboveVisible = heightAtLine(line) < doc.scrollTop updateLineHeight(line, line.height + widgetHeight(widget)) - if (aboveVisible) addToScrollPos(cm, null, widget.height) + if (aboveVisible) addToScrollTop(cm, widget.height) cm.curOp.forceUpdate = true } return true