mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-13 18:53:59 +02:00
fix scrollIntoView when selection is collapsed inside mark placeholder (#5143)
This commit is contained in:
5
.changeset/dry-nails-brake.md
Normal file
5
.changeset/dry-nails-brake.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix scrollIntoView when selection is collapsed inside mark placeholder
|
@@ -35,6 +35,7 @@ import {
|
|||||||
isDOMSelection,
|
isDOMSelection,
|
||||||
normalizeDOMPoint,
|
normalizeDOMPoint,
|
||||||
hasShadowRoot,
|
hasShadowRoot,
|
||||||
|
DOMText,
|
||||||
} from '../utils/dom'
|
} from '../utils/dom'
|
||||||
import { IS_CHROME, IS_FIREFOX, IS_ANDROID } from '../utils/environment'
|
import { IS_CHROME, IS_FIREFOX, IS_ANDROID } from '../utils/environment'
|
||||||
|
|
||||||
@@ -346,8 +347,15 @@ export const ReactEditor = {
|
|||||||
point.offset === end &&
|
point.offset === end &&
|
||||||
nextText?.hasAttribute('data-slate-mark-placeholder')
|
nextText?.hasAttribute('data-slate-mark-placeholder')
|
||||||
) {
|
) {
|
||||||
|
const domText = nextText.childNodes[0]
|
||||||
|
|
||||||
domPoint = [
|
domPoint = [
|
||||||
nextText,
|
// COMPAT: If we don't explicity set the dom point to be on the actual
|
||||||
|
// dom text element, chrome will put the selection behind the actual dom
|
||||||
|
// text element, causing domRange.getBoundingClientRect() calls on a collapsed
|
||||||
|
// selection to return incorrect zero values (https://bugs.chromium.org/p/chromium/issues/detail?id=435438)
|
||||||
|
// which will cause issues when scrolling to it.
|
||||||
|
domText instanceof DOMText ? domText : nextText,
|
||||||
nextText.textContent?.startsWith('\uFEFF') ? 1 : 0,
|
nextText.textContent?.startsWith('\uFEFF') ? 1 : 0,
|
||||||
]
|
]
|
||||||
break
|
break
|
||||||
|
Reference in New Issue
Block a user