mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-29 18:09:49 +02:00
scroll to the correct position (#1370)
This commit is contained in:
committed by
Ian Storm Taylor
parent
0b70ca85d5
commit
0a6d163ece
@@ -80,19 +80,19 @@ function scrollToSelection(selection) {
|
|||||||
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 || (width + xOffset) < left
|
||||||
? left - width / 2
|
? left - width / 2
|
||||||
: xOffset
|
: xOffset
|
||||||
|
|
||||||
const y = top < yOffset || height + yOffset < top
|
const y = top < yOffset || (height + yOffset) < top
|
||||||
? top - height / 2
|
? top - height / 2
|
||||||
: yOffset
|
: yOffset
|
||||||
|
|
||||||
if (isWindow) {
|
if (isWindow) {
|
||||||
window.scrollTo(x, y)
|
window.scrollTo(x, y)
|
||||||
} else {
|
} else {
|
||||||
scroller.scrollTop = scroller.scrollTop + y
|
scroller.scrollTop = y
|
||||||
scroller.scrollLeft = scroller.scrollLeft + x
|
scroller.scrollLeft = x
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user