1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-17 20:51:20 +02:00

fix(scroll-to-selection): use getClientRects when selectionRect.top/height is still 0 in Safari (#1446)

* fix(scroll-to-selection): use getClientRects when startContainer.length is 1

* fix(scroll-to-selection): rewrite and check if selectionRect.top/height still 0, use getClientRects

* fix(scroll-to-selection): identation whoopsie

* fix(scroll-to-selection): tabs !== spaces

* fix(scroll-to-selection): check for getClientRects length

* feat(scroll-to-selection): add IS_SAFARI check
This commit is contained in:
David Silva
2017-12-11 15:59:31 +01:00
committed by Ian Storm Taylor
parent 082fb53633
commit c58e53364f

View File

@@ -1,6 +1,7 @@
import getWindow from 'get-window'
import isBackward from 'selection-is-backward'
import { IS_SAFARI } from '../constants/environment'
/**
* CSS overflow values that would cause scrolling.
@@ -72,6 +73,7 @@ function scrollToSelection(selection) {
// for vertical scroll, although horizontal may be off by 1 character.
// https://bugs.webkit.org/show_bug.cgi?id=138949
// https://bugs.chromium.org/p/chromium/issues/detail?id=435438
if (IS_SAFARI) {
if (range.collapsed && selectionRect.top == 0 && selectionRect.height == 0) {
if (range.startOffset == 0) {
range.setEnd(range.endContainer, 1)
@@ -80,6 +82,13 @@ function scrollToSelection(selection) {
}
selectionRect = range.getBoundingClientRect()
if (selectionRect.top == 0 && selectionRect.height == 0) {
if (range.getClientRects().length) {
selectionRect = range.getClientRects()[0]
}
}
}
}
let width