From 986e49aaac1f9e2ada2689b4e94f39c0efd73268 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 21 Jul 2016 15:34:41 -0700 Subject: [PATCH] add splitBlock and splitInline transforms tests --- lib/models/state.js | 14 +++++---- .../fixtures/split-block/block-end/index.js | 29 ++++++++++++++++++ .../fixtures/split-block/block-end/input.yaml | 14 +++++++++ .../split-block/block-end/output.yaml | 20 +++++++++++++ .../split-block/block-middle/index.js | 29 ++++++++++++++++++ .../split-block/block-middle/input.yaml | 8 +++++ .../split-block/block-middle/output.yaml | 14 +++++++++ .../fixtures/split-block/block-start/index.js | 29 ++++++++++++++++++ .../split-block/block-start/input.yaml | 14 +++++++++ .../split-block/block-start/output.yaml | 20 +++++++++++++ .../fixtures/split-block/depth/index.js | 29 ++++++++++++++++++ .../fixtures/split-block/depth/input.yaml | 14 +++++++++ .../fixtures/split-block/depth/output.yaml | 26 ++++++++++++++++ .../index.js | 30 +++++++++++++++++++ .../input.yaml | 20 +++++++++++++ .../output.yaml | 26 ++++++++++++++++ .../with-delete-across-blocks/index.js | 30 +++++++++++++++++++ .../with-delete-across-blocks/input.yaml | 14 +++++++++ .../with-delete-across-blocks/output.yaml | 14 +++++++++ .../fixtures/split-block/with-delete/index.js | 29 ++++++++++++++++++ .../split-block/with-delete/input.yaml | 8 +++++ .../split-block/with-delete/output.yaml | 14 +++++++++ .../fixtures/split-block/with-inline/index.js | 29 ++++++++++++++++++ .../split-block/with-inline/input.yaml | 11 +++++++ .../split-block/with-inline/output.yaml | 20 +++++++++++++ .../fixtures/split-inline/block-end/index.js | 29 ++++++++++++++++++ .../split-inline/block-end/input.yaml | 11 +++++++ .../split-inline/block-end/output.yaml | 17 +++++++++++ .../split-inline/block-middle/index.js | 29 ++++++++++++++++++ .../split-inline/block-middle/input.yaml | 11 +++++++ .../split-inline/block-middle/output.yaml | 17 +++++++++++ .../split-inline/block-start/index.js | 29 ++++++++++++++++++ .../split-inline/block-start/input.yaml | 11 +++++++ .../split-inline/block-start/output.yaml | 17 +++++++++++ .../fixtures/split-inline/depth/index.js | 29 ++++++++++++++++++ .../fixtures/split-inline/depth/input.yaml | 14 +++++++++ .../fixtures/split-inline/depth/output.yaml | 20 +++++++++++++ .../split-inline/with-delete/index.js | 29 ++++++++++++++++++ .../split-inline/with-delete/input.yaml | 11 +++++++ .../split-inline/with-delete/output.yaml | 17 +++++++++++ .../fixtures/split-inline/with-marks/index.js | 29 ++++++++++++++++++ .../split-inline/with-marks/input.yaml | 13 ++++++++ .../split-inline/with-marks/output.yaml | 21 +++++++++++++ 43 files changed, 853 insertions(+), 6 deletions(-) create mode 100644 test/transforms/fixtures/split-block/block-end/index.js create mode 100644 test/transforms/fixtures/split-block/block-end/input.yaml create mode 100644 test/transforms/fixtures/split-block/block-end/output.yaml create mode 100644 test/transforms/fixtures/split-block/block-middle/index.js create mode 100644 test/transforms/fixtures/split-block/block-middle/input.yaml create mode 100644 test/transforms/fixtures/split-block/block-middle/output.yaml create mode 100644 test/transforms/fixtures/split-block/block-start/index.js create mode 100644 test/transforms/fixtures/split-block/block-start/input.yaml create mode 100644 test/transforms/fixtures/split-block/block-start/output.yaml create mode 100644 test/transforms/fixtures/split-block/depth/index.js create mode 100644 test/transforms/fixtures/split-block/depth/input.yaml create mode 100644 test/transforms/fixtures/split-block/depth/output.yaml create mode 100644 test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/index.js create mode 100644 test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/input.yaml create mode 100644 test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/output.yaml create mode 100644 test/transforms/fixtures/split-block/with-delete-across-blocks/index.js create mode 100644 test/transforms/fixtures/split-block/with-delete-across-blocks/input.yaml create mode 100644 test/transforms/fixtures/split-block/with-delete-across-blocks/output.yaml create mode 100644 test/transforms/fixtures/split-block/with-delete/index.js create mode 100644 test/transforms/fixtures/split-block/with-delete/input.yaml create mode 100644 test/transforms/fixtures/split-block/with-delete/output.yaml create mode 100644 test/transforms/fixtures/split-block/with-inline/index.js create mode 100644 test/transforms/fixtures/split-block/with-inline/input.yaml create mode 100644 test/transforms/fixtures/split-block/with-inline/output.yaml create mode 100644 test/transforms/fixtures/split-inline/block-end/index.js create mode 100644 test/transforms/fixtures/split-inline/block-end/input.yaml create mode 100644 test/transforms/fixtures/split-inline/block-end/output.yaml create mode 100644 test/transforms/fixtures/split-inline/block-middle/index.js create mode 100644 test/transforms/fixtures/split-inline/block-middle/input.yaml create mode 100644 test/transforms/fixtures/split-inline/block-middle/output.yaml create mode 100644 test/transforms/fixtures/split-inline/block-start/index.js create mode 100644 test/transforms/fixtures/split-inline/block-start/input.yaml create mode 100644 test/transforms/fixtures/split-inline/block-start/output.yaml create mode 100644 test/transforms/fixtures/split-inline/depth/index.js create mode 100644 test/transforms/fixtures/split-inline/depth/input.yaml create mode 100644 test/transforms/fixtures/split-inline/depth/output.yaml create mode 100644 test/transforms/fixtures/split-inline/with-delete/index.js create mode 100644 test/transforms/fixtures/split-inline/with-delete/input.yaml create mode 100644 test/transforms/fixtures/split-inline/with-delete/output.yaml create mode 100644 test/transforms/fixtures/split-inline/with-marks/index.js create mode 100644 test/transforms/fixtures/split-inline/with-marks/input.yaml create mode 100644 test/transforms/fixtures/split-inline/with-marks/output.yaml diff --git a/lib/models/state.js b/lib/models/state.js index f64a8e165..154915b63 100644 --- a/lib/models/state.js +++ b/lib/models/state.js @@ -791,17 +791,18 @@ class State extends new Record(DEFAULTS) { } /** - * Split the block node at the current selection. + * Split the block node at the current selection, to optional `depth`. * + * @param {Number} depth (optional) * @return {State} state */ - splitBlock() { + splitBlock(depth = 1) { let state = this let { document, selection } = state // Split the document. - document = document.splitBlockAtRange(selection) + document = document.splitBlockAtRange(selection, depth) // Determine what the selection should be after splitting. const { startKey } = selection @@ -814,17 +815,18 @@ class State extends new Record(DEFAULTS) { } /** - * Split the inline nodes at the current selection. + * Split the inline nodes at the current selection, to optional `depth`. * + * @param {Number} depth (optional) * @return {State} state */ - splitInline() { + splitInline(depth = Infinity) { let state = this let { document, selection } = state // Split the document. - document = document.splitInlineAtRange(selection) + document = document.splitInlineAtRange(selection, depth) // Determine what the selection should be after splitting. const { startKey } = selection diff --git a/test/transforms/fixtures/split-block/block-end/index.js b/test/transforms/fixtures/split-block/block-end/index.js new file mode 100644 index 000000000..eee223b08 --- /dev/null +++ b/test/transforms/fixtures/split-block/block-end/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: first.length, + focusKey: first.key, + focusOffset: first.length + }) + + const next = state + .transform() + .moveTo(range) + .splitBlock() + .apply() + + const updated = next.document.getTexts().get(1) + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-block/block-end/input.yaml b/test/transforms/fixtures/split-block/block-end/input.yaml new file mode 100644 index 000000000..4960c06f9 --- /dev/null +++ b/test/transforms/fixtures/split-block/block-end/input.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/split-block/block-end/output.yaml b/test/transforms/fixtures/split-block/block-end/output.yaml new file mode 100644 index 000000000..ca253468f --- /dev/null +++ b/test/transforms/fixtures/split-block/block-end/output.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: "" + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/split-block/block-middle/index.js b/test/transforms/fixtures/split-block/block-middle/index.js new file mode 100644 index 000000000..057e3199e --- /dev/null +++ b/test/transforms/fixtures/split-block/block-middle/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .splitBlock() + .apply() + + const updated = next.document.getTexts().get(1) + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-block/block-middle/input.yaml b/test/transforms/fixtures/split-block/block-middle/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/split-block/block-middle/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-block/block-middle/output.yaml b/test/transforms/fixtures/split-block/block-middle/output.yaml new file mode 100644 index 000000000..0537306d5 --- /dev/null +++ b/test/transforms/fixtures/split-block/block-middle/output.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: wo + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: rd diff --git a/test/transforms/fixtures/split-block/block-start/index.js b/test/transforms/fixtures/split-block/block-start/index.js new file mode 100644 index 000000000..d74190494 --- /dev/null +++ b/test/transforms/fixtures/split-block/block-start/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const second = texts.get(1) + const range = selection.merge({ + anchorKey: second.key, + anchorOffset: 0, + focusKey: second.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .splitBlock() + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-block/block-start/input.yaml b/test/transforms/fixtures/split-block/block-start/input.yaml new file mode 100644 index 000000000..4960c06f9 --- /dev/null +++ b/test/transforms/fixtures/split-block/block-start/input.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/split-block/block-start/output.yaml b/test/transforms/fixtures/split-block/block-start/output.yaml new file mode 100644 index 000000000..ca253468f --- /dev/null +++ b/test/transforms/fixtures/split-block/block-start/output.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: "" + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/split-block/depth/index.js b/test/transforms/fixtures/split-block/depth/index.js new file mode 100644 index 000000000..2b134cb3a --- /dev/null +++ b/test/transforms/fixtures/split-block/depth/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .splitBlock(Infinity) + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-block/depth/input.yaml b/test/transforms/fixtures/split-block/depth/input.yaml new file mode 100644 index 000000000..d1f658170 --- /dev/null +++ b/test/transforms/fixtures/split-block/depth/input.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: block + type: paragraph + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-block/depth/output.yaml b/test/transforms/fixtures/split-block/depth/output.yaml new file mode 100644 index 000000000..951fe547b --- /dev/null +++ b/test/transforms/fixtures/split-block/depth/output.yaml @@ -0,0 +1,26 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: block + type: paragraph + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: wo + - kind: block + type: paragraph + nodes: + - kind: block + type: paragraph + nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: rd diff --git a/test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/index.js b/test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/index.js new file mode 100644 index 000000000..dd5bab9f2 --- /dev/null +++ b/test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/index.js @@ -0,0 +1,30 @@ + +import assert from 'assert' + +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: 2, + focusKey: second.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .splitBlock() + .apply() + + const updated = next.document.getTexts().get(1) + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/input.yaml b/test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/input.yaml new file mode 100644 index 000000000..f302fa89a --- /dev/null +++ b/test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/input.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: one + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: inline + type: two + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/output.yaml b/test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/output.yaml new file mode 100644 index 000000000..68e8a525b --- /dev/null +++ b/test/transforms/fixtures/split-block/with-delete-across-blocks-and-inlines/output.yaml @@ -0,0 +1,26 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: one + nodes: + - kind: text + ranges: + - text: wo + - kind: block + type: paragraph + nodes: + - kind: inline + type: one + nodes: + - kind: text + ranges: + - text: "" + - kind: inline + type: two + nodes: + - kind: text + ranges: + - text: other diff --git a/test/transforms/fixtures/split-block/with-delete-across-blocks/index.js b/test/transforms/fixtures/split-block/with-delete-across-blocks/index.js new file mode 100644 index 000000000..9162b145c --- /dev/null +++ b/test/transforms/fixtures/split-block/with-delete-across-blocks/index.js @@ -0,0 +1,30 @@ + +import assert from 'assert' + +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: 2, + focusKey: second.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .splitBlock() + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-block/with-delete-across-blocks/input.yaml b/test/transforms/fixtures/split-block/with-delete-across-blocks/input.yaml new file mode 100644 index 000000000..4960c06f9 --- /dev/null +++ b/test/transforms/fixtures/split-block/with-delete-across-blocks/input.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: another diff --git a/test/transforms/fixtures/split-block/with-delete-across-blocks/output.yaml b/test/transforms/fixtures/split-block/with-delete-across-blocks/output.yaml new file mode 100644 index 000000000..69c1496d9 --- /dev/null +++ b/test/transforms/fixtures/split-block/with-delete-across-blocks/output.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: wo + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: other diff --git a/test/transforms/fixtures/split-block/with-delete/index.js b/test/transforms/fixtures/split-block/with-delete/index.js new file mode 100644 index 000000000..71f2c906e --- /dev/null +++ b/test/transforms/fixtures/split-block/with-delete/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 1, + focusKey: first.key, + focusOffset: 3 + }) + + const next = state + .transform() + .moveTo(range) + .splitBlock() + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-block/with-delete/input.yaml b/test/transforms/fixtures/split-block/with-delete/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/split-block/with-delete/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-block/with-delete/output.yaml b/test/transforms/fixtures/split-block/with-delete/output.yaml new file mode 100644 index 000000000..58febc8d5 --- /dev/null +++ b/test/transforms/fixtures/split-block/with-delete/output.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: w + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: d diff --git a/test/transforms/fixtures/split-block/with-inline/index.js b/test/transforms/fixtures/split-block/with-inline/index.js new file mode 100644 index 000000000..e9c2606fa --- /dev/null +++ b/test/transforms/fixtures/split-block/with-inline/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .splitBlock() + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-block/with-inline/input.yaml b/test/transforms/fixtures/split-block/with-inline/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/split-block/with-inline/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-block/with-inline/output.yaml b/test/transforms/fixtures/split-block/with-inline/output.yaml new file mode 100644 index 000000000..e48953921 --- /dev/null +++ b/test/transforms/fixtures/split-block/with-inline/output.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: wo + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: rd diff --git a/test/transforms/fixtures/split-inline/block-end/index.js b/test/transforms/fixtures/split-inline/block-end/index.js new file mode 100644 index 000000000..572bc022d --- /dev/null +++ b/test/transforms/fixtures/split-inline/block-end/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: first.length, + focusKey: first.key, + focusOffset: first.length + }) + + const next = state + .transform() + .moveTo(range) + .splitInline() + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-inline/block-end/input.yaml b/test/transforms/fixtures/split-inline/block-end/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/split-inline/block-end/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-inline/block-end/output.yaml b/test/transforms/fixtures/split-inline/block-end/output.yaml new file mode 100644 index 000000000..434d9939a --- /dev/null +++ b/test/transforms/fixtures/split-inline/block-end/output.yaml @@ -0,0 +1,17 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: "" diff --git a/test/transforms/fixtures/split-inline/block-middle/index.js b/test/transforms/fixtures/split-inline/block-middle/index.js new file mode 100644 index 000000000..657f372c5 --- /dev/null +++ b/test/transforms/fixtures/split-inline/block-middle/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .splitInline() + .apply() + + const updated = next.document.getTexts().get(1) + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-inline/block-middle/input.yaml b/test/transforms/fixtures/split-inline/block-middle/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/split-inline/block-middle/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-inline/block-middle/output.yaml b/test/transforms/fixtures/split-inline/block-middle/output.yaml new file mode 100644 index 000000000..6bdc40da8 --- /dev/null +++ b/test/transforms/fixtures/split-inline/block-middle/output.yaml @@ -0,0 +1,17 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: wo + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: rd diff --git a/test/transforms/fixtures/split-inline/block-start/index.js b/test/transforms/fixtures/split-inline/block-start/index.js new file mode 100644 index 000000000..2bd39f11d --- /dev/null +++ b/test/transforms/fixtures/split-inline/block-start/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .splitInline() + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-inline/block-start/input.yaml b/test/transforms/fixtures/split-inline/block-start/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/split-inline/block-start/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-inline/block-start/output.yaml b/test/transforms/fixtures/split-inline/block-start/output.yaml new file mode 100644 index 000000000..d3fe20ace --- /dev/null +++ b/test/transforms/fixtures/split-inline/block-start/output.yaml @@ -0,0 +1,17 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: "" + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-inline/depth/index.js b/test/transforms/fixtures/split-inline/depth/index.js new file mode 100644 index 000000000..835cbac0f --- /dev/null +++ b/test/transforms/fixtures/split-inline/depth/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .splitInline(1) + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-inline/depth/input.yaml b/test/transforms/fixtures/split-inline/depth/input.yaml new file mode 100644 index 000000000..f2e6a77cf --- /dev/null +++ b/test/transforms/fixtures/split-inline/depth/input.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-inline/depth/output.yaml b/test/transforms/fixtures/split-inline/depth/output.yaml new file mode 100644 index 000000000..478a597f4 --- /dev/null +++ b/test/transforms/fixtures/split-inline/depth/output.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: wo + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: rd diff --git a/test/transforms/fixtures/split-inline/with-delete/index.js b/test/transforms/fixtures/split-inline/with-delete/index.js new file mode 100644 index 000000000..6e6e379f1 --- /dev/null +++ b/test/transforms/fixtures/split-inline/with-delete/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 1, + focusKey: first.key, + focusOffset: 3 + }) + + const next = state + .transform() + .moveTo(range) + .splitInline() + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-inline/with-delete/input.yaml b/test/transforms/fixtures/split-inline/with-delete/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/split-inline/with-delete/input.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/split-inline/with-delete/output.yaml b/test/transforms/fixtures/split-inline/with-delete/output.yaml new file mode 100644 index 000000000..ccfc404a5 --- /dev/null +++ b/test/transforms/fixtures/split-inline/with-delete/output.yaml @@ -0,0 +1,17 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: w + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: d diff --git a/test/transforms/fixtures/split-inline/with-marks/index.js b/test/transforms/fixtures/split-inline/with-marks/index.js new file mode 100644 index 000000000..bde6e1347 --- /dev/null +++ b/test/transforms/fixtures/split-inline/with-marks/index.js @@ -0,0 +1,29 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .splitInline() + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.collapseToStartOf(updated).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/split-inline/with-marks/input.yaml b/test/transforms/fixtures/split-inline/with-marks/input.yaml new file mode 100644 index 000000000..4677d20e7 --- /dev/null +++ b/test/transforms/fixtures/split-inline/with-marks/input.yaml @@ -0,0 +1,13 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word + marks: + - type: bold diff --git a/test/transforms/fixtures/split-inline/with-marks/output.yaml b/test/transforms/fixtures/split-inline/with-marks/output.yaml new file mode 100644 index 000000000..378b77728 --- /dev/null +++ b/test/transforms/fixtures/split-inline/with-marks/output.yaml @@ -0,0 +1,21 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: wo + marks: + - type: bold + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: rd + marks: + - type: bold