Skip to content

Commit

Permalink
Fix splitNode range updates when selection is backward (ianstormtaylo…
Browse files Browse the repository at this point in the history
  • Loading branch information
Calyhre authored and ianstormtaylor committed Aug 19, 2019
1 parent b6a99ce commit 0edcc89
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/slate/src/models/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -799,16 +799,16 @@ class Value extends Record(DEFAULTS) {

value = value.mapRanges(range => {
const next = newDocument.getNextText(node.key)
const { start, end } = range
const { anchor, focus } = range

// If the start was after the split, move it to the next node.
if (node.key === start.key && position <= start.offset) {
range = range.moveStartTo(next.key, start.offset - position)
// If the anchor was after the split, move it to the next node.
if (node.key === anchor.key && position <= anchor.offset) {
range = range.moveAnchorTo(next.key, anchor.offset - position)
}

// If the end was after the split, move it to the next node.
if (node.key === end.key && position <= end.offset) {
range = range.moveEndTo(next.key, end.offset - position)
// If the focus was after the split, move it to the next node.
if (node.key === focus.key && position <= focus.offset) {
range = range.moveFocusTo(next.key, focus.offset - position)
}

range = range.updatePoints(point => point.setPath(null))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @jsx h */

import h from '../../../helpers/h'

export default function(editor) {
editor.removeMark('bold')
}

export const input = (
<value>
<document>
<paragraph>
<b>
wor<focus />d<anchor />
</b>
</paragraph>
</document>
</value>
)

export const output = (
<value>
<document>
<paragraph>
<b>wor</b>
<focus />d<anchor />
</paragraph>
</document>
</value>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @jsx h */

import h from '../../../helpers/h'

export default function(editor) {
editor.removeMark('bold')
}

export const input = (
<value>
<document>
<paragraph>
<b>
wor<anchor />d<focus />
</b>
</paragraph>
</document>
</value>
)

export const output = (
<value>
<document>
<paragraph>
<b>wor</b>
<anchor />d<focus />
</paragraph>
</document>
</value>
)

0 comments on commit 0edcc89

Please sign in to comment.