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:
committed by
Ian Storm Taylor
parent
082fb53633
commit
c58e53364f
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import getWindow from 'get-window'
|
import getWindow from 'get-window'
|
||||||
import isBackward from 'selection-is-backward'
|
import isBackward from 'selection-is-backward'
|
||||||
|
import { IS_SAFARI } from '../constants/environment'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CSS overflow values that would cause scrolling.
|
* CSS overflow values that would cause scrolling.
|
||||||
@@ -72,14 +73,22 @@ function scrollToSelection(selection) {
|
|||||||
// for vertical scroll, although horizontal may be off by 1 character.
|
// for vertical scroll, although horizontal may be off by 1 character.
|
||||||
// https://bugs.webkit.org/show_bug.cgi?id=138949
|
// https://bugs.webkit.org/show_bug.cgi?id=138949
|
||||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=435438
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=435438
|
||||||
if (range.collapsed && selectionRect.top == 0 && selectionRect.height == 0) {
|
if (IS_SAFARI) {
|
||||||
if (range.startOffset == 0) {
|
if (range.collapsed && selectionRect.top == 0 && selectionRect.height == 0) {
|
||||||
range.setEnd(range.endContainer, 1)
|
if (range.startOffset == 0) {
|
||||||
} else {
|
range.setEnd(range.endContainer, 1)
|
||||||
range.setStart(range.startContainer, range.startOffset - 1)
|
} else {
|
||||||
}
|
range.setStart(range.startContainer, range.startOffset - 1)
|
||||||
|
}
|
||||||
|
|
||||||
selectionRect = range.getBoundingClientRect()
|
selectionRect = range.getBoundingClientRect()
|
||||||
|
|
||||||
|
if (selectionRect.top == 0 && selectionRect.height == 0) {
|
||||||
|
if (range.getClientRects().length) {
|
||||||
|
selectionRect = range.getClientRects()[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let width
|
let width
|
||||||
|
Reference in New Issue
Block a user