1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-19 05:31:56 +02:00
This commit is contained in:
Ian Storm Taylor
2017-10-31 19:06:01 -07:00
parent b76c26e980
commit 6b716a0d8c

View File

@@ -24,7 +24,7 @@ function findScrollContainer(el) {
const window = getWindow(el) const window = getWindow(el)
let parent = el.parentNode let parent = el.parentNode
let scroller = window let scroller = window
while (!scroller) { while (!scroller) {
if (!parent.parentNode) break if (!parent.parentNode) break
const style = window.getComputedStyle(parent) const style = window.getComputedStyle(parent)
@@ -34,10 +34,10 @@ function findScrollContainer(el) {
scroller = parent scroller = parent
break break
} }
parent = parent.parentNode parent = parent.parentNode
} }
return scroller return scroller
} }
@@ -60,7 +60,7 @@ function scrollToSelection(selection) {
let height let height
let yOffset let yOffset
let xOffset let xOffset
if (isWindow) { if (isWindow) {
const { innerWidth, innerHeight, pageYOffset, pageXOffset } = scroller const { innerWidth, innerHeight, pageYOffset, pageXOffset } = scroller
width = innerWidth width = innerWidth
@@ -74,10 +74,10 @@ function scrollToSelection(selection) {
yOffset = scrollTop yOffset = scrollTop
xOffset = scrollLeft xOffset = scrollLeft
} }
const top = (backward ? rect.top : rect.bottom) + yOffset const top = (backward ? rect.top : rect.bottom) + yOffset
const left = (backward ? rect.left : rect.right) + xOffset const left = (backward ? rect.left : rect.right) + xOffset
const x = left < yOffset || innerWidth + xOffset < left const x = left < yOffset || innerWidth + xOffset < left
? left - width / 2 ? left - width / 2
: xOffset : xOffset