mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 04:04:06 +02:00
fix findRange for text nodes next to inlines (#1298)
This commit is contained in:
@@ -514,36 +514,36 @@ function AfterPlugin(options = {}) {
|
||||
// an inline is selected, we need to handle these hotkeys manually because
|
||||
// browsers won't know what to do.
|
||||
if (HOTKEYS.COLLAPSE_CHAR_BACKWARD(event)) {
|
||||
const { isInVoid, previousText, document } = state
|
||||
const { document, isInVoid, previousText, startText } = state
|
||||
const isPreviousInVoid = previousText && document.hasVoidParent(previousText.key)
|
||||
if (isInVoid || isPreviousInVoid) {
|
||||
if (isInVoid || isPreviousInVoid || startText.text == '') {
|
||||
event.preventDefault()
|
||||
return change.collapseCharBackward()
|
||||
}
|
||||
}
|
||||
|
||||
if (HOTKEYS.COLLAPSE_CHAR_FORWARD(event)) {
|
||||
const { isInVoid, nextText, document } = state
|
||||
const { document, isInVoid, nextText, startText } = state
|
||||
const isNextInVoid = nextText && document.hasVoidParent(nextText.key)
|
||||
if (isInVoid || isNextInVoid) {
|
||||
if (isInVoid || isNextInVoid || startText.text == '') {
|
||||
event.preventDefault()
|
||||
return change.collapseCharForward()
|
||||
}
|
||||
}
|
||||
|
||||
if (HOTKEYS.EXTEND_CHAR_BACKWARD(event)) {
|
||||
const { isInVoid, previousText, document } = state
|
||||
const { document, isInVoid, previousText, startText } = state
|
||||
const isPreviousInVoid = previousText && document.hasVoidParent(previousText.key)
|
||||
if (isInVoid || isPreviousInVoid) {
|
||||
if (isInVoid || isPreviousInVoid || startText.text == '') {
|
||||
event.preventDefault()
|
||||
return change.extendCharBackward()
|
||||
}
|
||||
}
|
||||
|
||||
if (HOTKEYS.EXTEND_CHAR_FORWARD(event)) {
|
||||
const { isInVoid, nextText, document } = state
|
||||
const { document, isInVoid, nextText, startText } = state
|
||||
const isNextInVoid = nextText && document.hasVoidParent(nextText.key)
|
||||
if (isInVoid || isNextInVoid) {
|
||||
if (isInVoid || isNextInVoid || startText.text == '') {
|
||||
event.preventDefault()
|
||||
return change.extendCharForward()
|
||||
}
|
||||
|
@@ -56,6 +56,12 @@ function findPoint(nativeNode, nativeOffset, state) {
|
||||
offset = node.textContent.length
|
||||
}
|
||||
|
||||
// COMPAT: If the parent node is a Slate zero-width space, this is because the
|
||||
// text node has no characters, so the offset can only be zero.
|
||||
if (offset != 0 && parentNode.getAttribute('data-slate-zero-width')) {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
// Get the string value of the offset key attribute.
|
||||
const offsetKey = rangeNode.getAttribute(OFFSET_KEY_ATTRIBUTE)
|
||||
if (!offsetKey) return null
|
||||
|
Reference in New Issue
Block a user