1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-12 18:24:03 +02:00

Fix selection getting incorrectly set in readonly shadow dom case (#5259)

* Fix selection getting incorrectly set in readonly shadow dom case

* Add changeset for slate react
This commit is contained in:
Jaclyn Feminella
2023-01-14 08:00:38 -05:00
committed by GitHub
parent 0df29a9dd7
commit d7de564d62
3 changed files with 15 additions and 5 deletions

View File

@@ -726,7 +726,7 @@ export const ReactEditor = {
// `isCollapsed` for a Selection that comes from a ShadowRoot.
// (2020/08/08)
// https://bugs.chromium.org/p/chromium/issues/detail?id=447523
if (IS_CHROME && hasShadowRoot()) {
if (IS_CHROME && hasShadowRoot(anchorNode)) {
isCollapsed =
domRange.anchorNode === domRange.focusNode &&
domRange.anchorOffset === domRange.focusOffset

View File

@@ -137,10 +137,15 @@ export const normalizeDOMPoint = (domPoint: DOMPoint): DOMPoint => {
* Determines wether the active element is nested within a shadowRoot
*/
export const hasShadowRoot = () => {
return !!(
window.document.activeElement && window.document.activeElement.shadowRoot
)
export const hasShadowRoot = (node: Node | null) => {
let parent = node && node.parentNode
while (parent) {
if (parent.toString() === '[object ShadowRoot]') {
return true
}
parent = parent.parentNode
}
return false
}
/**