1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-13 18:53:59 +02:00

fix getting index for inline node in unwrapInlineAtRange, fixes #620 (#648)

This commit is contained in:
Aliaksei Simanchyk
2017-03-05 04:26:35 +02:00
committed by Ian Storm Taylor
parent 54ecb63f9d
commit 698a88a24f
4 changed files with 47 additions and 1 deletions

View File

@@ -1032,7 +1032,7 @@ Transforms.unwrapInlineAtRange = (transform, range, properties, options = {}) =>
.toList()
inlines.forEach((inline) => {
const parent = document.getParent(inline.key)
const parent = transform.state.document.getParent(inline.key)
const index = parent.nodes.indexOf(inline)
inline.nodes.forEach((child, i) => {

View File

@@ -0,0 +1,18 @@
export default function (state) {
const { document, selection } = state;
const texts = document.getTexts();
const first = texts.first();
const second = texts.last();
const range = selection.merge({
anchorKey: first.key,
anchorOffset: 0,
focusKey: second.key,
focusOffset: 0
});
return state
.transform()
.unwrapInlineAtRange(range, 'link')
.apply()
}

View File

@@ -0,0 +1,21 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: ""
- kind: inline
type: link
nodes:
- kind: text
text: Hello
- kind: text
text: " "
- kind: inline
type: link
nodes:
- kind: text
text: world!
- kind: text
text: ""

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: "Hello world!"