1
0
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:
Ian Storm Taylor
2017-10-26 09:26:58 -07:00
committed by GitHub
parent c170e7940e
commit 1235a0a8c5
2 changed files with 14 additions and 8 deletions

View File

@@ -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()
}

View File

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