1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-22 16:17:17 +01:00

fix selection setting in wrapInline transform

This commit is contained in:
Ian Storm Taylor 2016-07-28 12:32:33 -07:00
parent d80bda5802
commit 5f73c63208
4 changed files with 20 additions and 5 deletions

View File

@ -444,7 +444,7 @@ class Selection extends new Record(DEFAULTS) {
anchorOffset: 0,
focusKey: end.key,
focusOffset: end.length,
isBackward: null
isBackward: start == end ? false : null
})
}

View File

@ -1056,6 +1056,9 @@ class State extends new Record(DEFAULTS) {
wrapInline(type, data) {
let state = this
let { document, selection } = state
const { startKey } = selection
const previous = document.getPreviousText(startKey)
document = document.wrapInlineAtRange(selection, type, data)
// Determine what the selection should be after wrapping.
@ -1064,15 +1067,15 @@ class State extends new Record(DEFAULTS) {
}
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.normalize(document)
}
else {
const text = document.getNextText(selection.startKey)
selection = selection.moveToRangeOf(text)
selection = selection.normalize(document)
}
state = state.merge({ document, selection })

View File

@ -1025,7 +1025,7 @@ const Transforms = {
: node.updateDescendant(parent.merge({ nodes }))
})
return node
return node.normalize()
}
}

View File

@ -19,5 +19,17 @@ export default function (state) {
.wrapInline('outer')
.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
}