prosemirror-view
Advanced tools
Comparing version 1.5.3 to 1.6.0
@@ -0,1 +1,13 @@ | ||
## 1.6.0 (2018-09-27) | ||
### Bug fixes | ||
Fixes a corner case in which DecorationSet.map would map decorations to incorrect new positions. | ||
When the editor contains scrollable elements, scrolling the cursor into view also scrolls those. | ||
### New features | ||
The `scrollMargin` and `scrollThreshold` props may now hold `{left, right, top, bottom}` objects to set different margins and thresholds for different sides. Make scrolling from a given start node more robust | ||
## 1.5.3 (2018-09-24) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "prosemirror-view", | ||
"version": "1.5.3", | ||
"version": "1.6.0", | ||
"description": "ProseMirror's view component", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -507,4 +507,4 @@ function compareObjs(a, b) { | ||
} else { | ||
children.splice(i, 3) | ||
i -= 3 | ||
children[i + 1] = -2 | ||
mustRebuild = true | ||
} | ||
@@ -518,7 +518,7 @@ } else { | ||
if (mustRebuild) { | ||
let decorations = mapAndGatherRemainingDecorations(children, newLocal ? moveSpans(newLocal, offset) : [], mapping, | ||
let decorations = mapAndGatherRemainingDecorations(children, oldChildren, newLocal ? moveSpans(newLocal, offset) : [], mapping, | ||
offset, oldOffset, options) | ||
let built = buildTree(decorations, node, 0, options) | ||
newLocal = built.local | ||
for (let i = 0; i < children.length; i += 3) if (children[i + 1] == -1) { | ||
for (let i = 0; i < children.length; i += 3) if (children[i + 1] < 0) { | ||
children.splice(i, 3) | ||
@@ -547,3 +547,3 @@ i -= 3 | ||
function mapAndGatherRemainingDecorations(children, decorations, mapping, offset, oldOffset, options) { | ||
function mapAndGatherRemainingDecorations(children, oldChildren, decorations, mapping, offset, oldOffset, options) { | ||
// Gather all decorations from the remaining marked children | ||
@@ -560,3 +560,3 @@ function gather(set, oldOffset) { | ||
for (let i = 0; i < children.length; i += 3) if (children[i + 1] == -1) | ||
gather(children[i + 2], children[i] + oldOffset + 1) | ||
gather(children[i + 2], oldChildren[i] + oldOffset + 1) | ||
@@ -563,0 +563,0 @@ return decorations |
@@ -8,19 +8,23 @@ import {textRange, parentNode} from "./dom" | ||
export function scrollRectIntoView(view, rect) { | ||
let scrollThreshold = view.someProp("scrollThreshold") || 0, scrollMargin = view.someProp("scrollMargin") | ||
function getSide(value, side) { | ||
return typeof value == "number" ? value : value[side] | ||
} | ||
export function scrollRectIntoView(view, rect, startDOM) { | ||
let scrollThreshold = view.someProp("scrollThreshold") || 0, scrollMargin = view.someProp("scrollMargin") || 5 | ||
let doc = view.dom.ownerDocument, win = doc.defaultView | ||
if (scrollMargin == null) scrollMargin = 5 | ||
for (let parent = view.dom;; parent = parentNode(parent)) { | ||
for (let parent = startDOM || view.dom;; parent = parentNode(parent)) { | ||
if (!parent) break | ||
if (parent.nodeType != 1) continue | ||
let atTop = parent == doc.body || parent.nodeType != 1 | ||
let bounding = atTop ? windowRect(win) : parent.getBoundingClientRect() | ||
let moveX = 0, moveY = 0 | ||
if (rect.top < bounding.top + scrollThreshold) | ||
moveY = -(bounding.top - rect.top + scrollMargin) | ||
else if (rect.bottom > bounding.bottom - scrollThreshold) | ||
moveY = rect.bottom - bounding.bottom + scrollMargin | ||
if (rect.left < bounding.left + scrollThreshold) | ||
moveX = -(bounding.left - rect.left + scrollMargin) | ||
else if (rect.right > bounding.right - scrollThreshold) | ||
moveX = rect.right - bounding.right + scrollMargin | ||
if (rect.top < bounding.top + getSide(scrollThreshold, "top")) | ||
moveY = -(bounding.top - rect.top + getSide(scrollMargin, "top")) | ||
else if (rect.bottom > bounding.bottom - getSide(scrollThreshold, "bottom")) | ||
moveY = rect.bottom - bounding.bottom + getSide(scrollMargin, "bottom") | ||
if (rect.left < bounding.left + getSide(scrollThreshold, "left")) | ||
moveX = -(bounding.left - rect.left + getSide(scrollMargin, "left")) | ||
else if (rect.right > bounding.right - getSide(scrollThreshold, "right")) | ||
moveX = rect.right - bounding.right + getSide(scrollMargin, "right") | ||
if (moveX || moveY) { | ||
@@ -27,0 +31,0 @@ if (atTop) { |
@@ -140,8 +140,9 @@ import {Mark} from "prosemirror-model" | ||
} else if (scroll == "to selection") { | ||
let startDOM = this.root.getSelection().focusNode | ||
if (this.someProp("handleScrollToSelection", f => f(this))) | ||
{} // Handled | ||
else if (state.selection instanceof NodeSelection) | ||
scrollRectIntoView(this, this.docView.domAfterPos(state.selection.from).getBoundingClientRect()) | ||
scrollRectIntoView(this, this.docView.domAfterPos(state.selection.from).getBoundingClientRect(), startDOM) | ||
else | ||
scrollRectIntoView(this, this.coordsAtPos(state.selection.head)) | ||
scrollRectIntoView(this, this.coordsAtPos(state.selection.head), startDOM) | ||
} else if (oldScrollPos) { | ||
@@ -544,3 +545,3 @@ resetScrollPos(oldScrollPos) | ||
// | ||
// scrollThreshold:: ?number | ||
// scrollThreshold:: ?number | {top: number, right: number, bottom: number, left: number} | ||
// Determines the distance (in pixels) between the cursor and the | ||
@@ -550,3 +551,3 @@ // end of the visible viewport at which point, when scrolling the | ||
// | ||
// scrollMargin:: ?number | ||
// scrollMargin:: ?number | {top: number, right: number, bottom: number, left: number} | ||
// Determines the extra space (in pixels) that is left above or | ||
@@ -553,0 +554,0 @@ // below the cursor when it is scrolled into view. Defaults to 5. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
738700
8331