From 0a6d163ecef9178e52596b7654c951bcb1b39cf1 Mon Sep 17 00:00:00 2001 From: Irwan Fario Subastian Date: Thu, 2 Nov 2017 15:28:50 +1100 Subject: [PATCH] scroll to the correct position (#1370) --- packages/slate-react/src/utils/scroll-to-selection.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/slate-react/src/utils/scroll-to-selection.js b/packages/slate-react/src/utils/scroll-to-selection.js index 121a12bf5..49c7fce15 100644 --- a/packages/slate-react/src/utils/scroll-to-selection.js +++ b/packages/slate-react/src/utils/scroll-to-selection.js @@ -80,19 +80,19 @@ function scrollToSelection(selection) { const top = (backward ? rect.top : rect.bottom) + yOffset const left = (backward ? rect.left : rect.right) + xOffset - const x = left < yOffset || innerWidth + xOffset < left + const x = left < yOffset || (width + xOffset) < left ? left - width / 2 : xOffset - const y = top < yOffset || height + yOffset < top + const y = top < yOffset || (height + yOffset) < top ? top - height / 2 : yOffset if (isWindow) { window.scrollTo(x, y) } else { - scroller.scrollTop = scroller.scrollTop + y - scroller.scrollLeft = scroller.scrollLeft + x + scroller.scrollTop = y + scroller.scrollLeft = x } }