mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-31 02:49:56 +02:00
fix selection setting in wrapInline transform
This commit is contained in:
@@ -444,7 +444,7 @@ class Selection extends new Record(DEFAULTS) {
|
|||||||
anchorOffset: 0,
|
anchorOffset: 0,
|
||||||
focusKey: end.key,
|
focusKey: end.key,
|
||||||
focusOffset: end.length,
|
focusOffset: end.length,
|
||||||
isBackward: null
|
isBackward: start == end ? false : null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1056,6 +1056,9 @@ class State extends new Record(DEFAULTS) {
|
|||||||
wrapInline(type, data) {
|
wrapInline(type, data) {
|
||||||
let state = this
|
let state = this
|
||||||
let { document, selection } = state
|
let { document, selection } = state
|
||||||
|
const { startKey } = selection
|
||||||
|
const previous = document.getPreviousText(startKey)
|
||||||
|
|
||||||
document = document.wrapInlineAtRange(selection, type, data)
|
document = document.wrapInlineAtRange(selection, type, data)
|
||||||
|
|
||||||
// Determine what the selection should be after wrapping.
|
// Determine what the selection should be after wrapping.
|
||||||
@@ -1064,15 +1067,15 @@ class State extends new Record(DEFAULTS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (selection.startOffset == 0) {
|
else if (selection.startOffset == 0) {
|
||||||
const text = document.getDescendant(selection.startKey)
|
const text = previous
|
||||||
|
? document.getNextText(previous)
|
||||||
|
: document.getTexts().first()
|
||||||
selection = selection.moveToRangeOf(text)
|
selection = selection.moveToRangeOf(text)
|
||||||
selection = selection.normalize(document)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
const text = document.getNextText(selection.startKey)
|
const text = document.getNextText(selection.startKey)
|
||||||
selection = selection.moveToRangeOf(text)
|
selection = selection.moveToRangeOf(text)
|
||||||
selection = selection.normalize(document)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state = state.merge({ document, selection })
|
state = state.merge({ document, selection })
|
||||||
|
@@ -1025,7 +1025,7 @@ const Transforms = {
|
|||||||
: node.updateDescendant(parent.merge({ nodes }))
|
: node.updateDescendant(parent.merge({ nodes }))
|
||||||
})
|
})
|
||||||
|
|
||||||
return node
|
return node.normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -19,5 +19,17 @@ export default function (state) {
|
|||||||
.wrapInline('outer')
|
.wrapInline('outer')
|
||||||
.apply()
|
.apply()
|
||||||
|
|
||||||
|
const updated = next.document.getTexts().get(1)
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
next.selection.toJS(),
|
||||||
|
range.merge({
|
||||||
|
anchorKey: updated.key,
|
||||||
|
anchorOffset: 0,
|
||||||
|
focusKey: updated.key,
|
||||||
|
focusOffset: updated.length
|
||||||
|
}).toJS()
|
||||||
|
)
|
||||||
|
|
||||||
return next
|
return next
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user