1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-13 10:44:02 +02:00

fix scrollIntoView when selection is collapsed inside mark placeholder (#5143)

This commit is contained in:
Eric Meier
2022-10-03 17:00:20 +02:00
committed by GitHub
parent e8614d1eec
commit 347865cafc
2 changed files with 14 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Fix scrollIntoView when selection is collapsed inside mark placeholder

View File

@@ -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