mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-13 18:53:59 +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:
5
.changeset/fast-apricots-deliver.md
Normal file
5
.changeset/fast-apricots-deliver.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Updates the selection correctly in readonly shadowdom
|
@@ -726,7 +726,7 @@ export const ReactEditor = {
|
|||||||
// `isCollapsed` for a Selection that comes from a ShadowRoot.
|
// `isCollapsed` for a Selection that comes from a ShadowRoot.
|
||||||
// (2020/08/08)
|
// (2020/08/08)
|
||||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=447523
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=447523
|
||||||
if (IS_CHROME && hasShadowRoot()) {
|
if (IS_CHROME && hasShadowRoot(anchorNode)) {
|
||||||
isCollapsed =
|
isCollapsed =
|
||||||
domRange.anchorNode === domRange.focusNode &&
|
domRange.anchorNode === domRange.focusNode &&
|
||||||
domRange.anchorOffset === domRange.focusOffset
|
domRange.anchorOffset === domRange.focusOffset
|
||||||
|
@@ -137,10 +137,15 @@ export const normalizeDOMPoint = (domPoint: DOMPoint): DOMPoint => {
|
|||||||
* Determines wether the active element is nested within a shadowRoot
|
* Determines wether the active element is nested within a shadowRoot
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const hasShadowRoot = () => {
|
export const hasShadowRoot = (node: Node | null) => {
|
||||||
return !!(
|
let parent = node && node.parentNode
|
||||||
window.document.activeElement && window.document.activeElement.shadowRoot
|
while (parent) {
|
||||||
)
|
if (parent.toString() === '[object ShadowRoot]') {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
parent = parent.parentNode
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user