diff --git a/test/transforms/fixtures/insert-fragment/end-block/fragment.yaml b/test/transforms/fixtures/insert-fragment/end-block/fragment.yaml new file mode 100644 index 000000000..3466f52fd --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/end-block/fragment.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/end-block/index.js b/test/transforms/fixtures/insert-fragment/end-block/index.js new file mode 100644 index 000000000..5cdcd6cab --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/end-block/index.js @@ -0,0 +1,40 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const last = fragment.getTexts().last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: first.length, + focusKey: first.key, + focusOffset: first.length + }) + + const next = state + .transform() + .moveTo(range) + .insertFragment(fragment) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: first.key, + anchorOffset: first.length + last.length, + focusKey: first.key, + focusOffset: first.length + last.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/end-block/input.yaml b/test/transforms/fixtures/insert-fragment/end-block/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/end-block/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/insert-fragment/end-block/output.yaml b/test/transforms/fixtures/insert-fragment/end-block/output.yaml new file mode 100644 index 000000000..76e16266b --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/end-block/output.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: wordfragment diff --git a/test/transforms/fixtures/insert-fragment/end-inline/fragment.yaml b/test/transforms/fixtures/insert-fragment/end-inline/fragment.yaml new file mode 100644 index 000000000..3466f52fd --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/end-inline/fragment.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/end-inline/index.js b/test/transforms/fixtures/insert-fragment/end-inline/index.js new file mode 100644 index 000000000..01b07f352 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/end-inline/index.js @@ -0,0 +1,41 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + 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) + .insertFragment(fragment) + .apply() + + const last = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: last.key, + anchorOffset: last.length, + focusKey: last.key, + focusOffset: last.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/end-inline/input.yaml b/test/transforms/fixtures/insert-fragment/end-inline/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/end-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/insert-fragment/end-inline/output.yaml b/test/transforms/fixtures/insert-fragment/end-inline/output.yaml new file mode 100644 index 000000000..b688f1365 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/end-inline/output.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/fragment.yaml b/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/fragment.yaml new file mode 100644 index 000000000..9cd8094c7 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/fragment.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment one + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment two diff --git a/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/index.js b/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/index.js new file mode 100644 index 000000000..87c24c702 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/index.js @@ -0,0 +1,42 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const last = fragment.getTexts().last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .insertFragment(fragment) + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: updated.key, + anchorOffset: last.length, + focusKey: updated.key, + focusOffset: last.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/input.yaml b/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/output.yaml b/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/output.yaml new file mode 100644 index 000000000..e9cccfc57 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-block-multiple-fragment-blocks/output.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: wofragment one + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment tword diff --git a/test/transforms/fixtures/insert-fragment/middle-block/fragment.yaml b/test/transforms/fixtures/insert-fragment/middle-block/fragment.yaml new file mode 100644 index 000000000..3466f52fd --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-block/fragment.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/middle-block/index.js b/test/transforms/fixtures/insert-fragment/middle-block/index.js new file mode 100644 index 000000000..155bdd26f --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-block/index.js @@ -0,0 +1,40 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const last = fragment.getTexts().last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .insertFragment(fragment) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: first.key, + anchorOffset: range.anchorOffset + last.length, + focusKey: first.key, + focusOffset: range.focusOffset + last.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/middle-block/input.yaml b/test/transforms/fixtures/insert-fragment/middle-block/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-block/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/insert-fragment/middle-block/output.yaml b/test/transforms/fixtures/insert-fragment/middle-block/output.yaml new file mode 100644 index 000000000..781a28f42 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-block/output.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: wofragmentrd diff --git a/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/fragment.yaml b/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/fragment.yaml new file mode 100644 index 000000000..4a6565303 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/fragment.yaml @@ -0,0 +1,11 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: inline + type: hashtag + nodes: + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/index.js b/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/index.js new file mode 100644 index 000000000..edb676e9a --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/index.js @@ -0,0 +1,42 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const last = fragment.getTexts().last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .insertFragment(fragment) + .apply() + + const updated = next.document.getTexts().get(1) + + // assert.deepEqual( + // next.selection.toJS(), + // range.merge({ + // anchorKey: updated.key, + // anchorOffset: last.length, + // focusKey: updated.key, + // focusOffset: last.length + // }).toJS() + // ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/input.yaml b/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-inline-fragment-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/insert-fragment/middle-inline-fragment-inline/output.yaml b/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/output.yaml new file mode 100644 index 000000000..f1f97eac7 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-inline-fragment-inline/output.yaml @@ -0,0 +1,23 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: wo + - kind: inline + type: hashtag + nodes: + - kind: text + ranges: + - text: fragment + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: rd diff --git a/test/transforms/fixtures/insert-fragment/middle-inline/fragment.yaml b/test/transforms/fixtures/insert-fragment/middle-inline/fragment.yaml new file mode 100644 index 000000000..3466f52fd --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-inline/fragment.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/middle-inline/index.js b/test/transforms/fixtures/insert-fragment/middle-inline/index.js new file mode 100644 index 000000000..87c24c702 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-inline/index.js @@ -0,0 +1,42 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const last = fragment.getTexts().last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: first.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .insertFragment(fragment) + .apply() + + const updated = next.document.getTexts().last() + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: updated.key, + anchorOffset: last.length, + focusKey: updated.key, + focusOffset: last.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/middle-inline/input.yaml b/test/transforms/fixtures/insert-fragment/middle-inline/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-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/insert-fragment/middle-inline/output.yaml b/test/transforms/fixtures/insert-fragment/middle-inline/output.yaml new file mode 100644 index 000000000..7b1d5b6ea --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/middle-inline/output.yaml @@ -0,0 +1,20 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: wo + - kind: text + ranges: + - text: fragment + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: rd diff --git a/test/transforms/fixtures/insert-fragment/start-block/fragment.yaml b/test/transforms/fixtures/insert-fragment/start-block/fragment.yaml new file mode 100644 index 000000000..3466f52fd --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-block/fragment.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/start-block/index.js b/test/transforms/fixtures/insert-fragment/start-block/index.js new file mode 100644 index 000000000..fc2d3d8d7 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-block/index.js @@ -0,0 +1,42 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const last = fragment.getTexts().last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .insertFragment(fragment) + .apply() + + const updated = next.document.getTexts().first() + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: updated.key, + anchorOffset: last.length, + focusKey: updated.key, + focusOffset: last.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/start-block/input.yaml b/test/transforms/fixtures/insert-fragment/start-block/input.yaml new file mode 100644 index 000000000..b1be31e90 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-block/input.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/insert-fragment/start-block/output.yaml b/test/transforms/fixtures/insert-fragment/start-block/output.yaml new file mode 100644 index 000000000..6b026e5b2 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-block/output.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: fragmentword diff --git a/test/transforms/fixtures/insert-fragment/start-inline/fragment.yaml b/test/transforms/fixtures/insert-fragment/start-inline/fragment.yaml new file mode 100644 index 000000000..3466f52fd --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-inline/fragment.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/start-inline/index.js b/test/transforms/fixtures/insert-fragment/start-inline/index.js new file mode 100644 index 000000000..fc2d3d8d7 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-inline/index.js @@ -0,0 +1,42 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const last = fragment.getTexts().last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 0, + focusKey: first.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .insertFragment(fragment) + .apply() + + const updated = next.document.getTexts().first() + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: updated.key, + anchorOffset: last.length, + focusKey: updated.key, + focusOffset: last.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/start-inline/input.yaml b/test/transforms/fixtures/insert-fragment/start-inline/input.yaml new file mode 100644 index 000000000..395351b4f --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-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/insert-fragment/start-inline/output.yaml b/test/transforms/fixtures/insert-fragment/start-inline/output.yaml new file mode 100644 index 000000000..2f3ee719b --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-inline/output.yaml @@ -0,0 +1,14 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: fragment + - kind: inline + type: link + nodes: + - kind: text + ranges: + - text: word diff --git a/test/transforms/fixtures/insert-fragment/start-second-block/fragment.yaml b/test/transforms/fixtures/insert-fragment/start-second-block/fragment.yaml new file mode 100644 index 000000000..3466f52fd --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-second-block/fragment.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/start-second-block/index.js b/test/transforms/fixtures/insert-fragment/start-second-block/index.js new file mode 100644 index 000000000..8fd753ff3 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-second-block/index.js @@ -0,0 +1,42 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + const { document, selection } = state + const texts = document.getTexts() + const second = texts.get(1) + const last = fragment.getTexts().last() + const range = selection.merge({ + anchorKey: second.key, + anchorOffset: 0, + focusKey: second.key, + focusOffset: 0 + }) + + const next = state + .transform() + .moveTo(range) + .insertFragment(fragment) + .apply() + + const updated = next.document.getTexts().get(1) + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: updated.key, + anchorOffset: last.length, + focusKey: updated.key, + focusOffset: last.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/start-second-block/input.yaml b/test/transforms/fixtures/insert-fragment/start-second-block/input.yaml new file mode 100644 index 000000000..4960c06f9 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-second-block/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/insert-fragment/start-second-block/output.yaml b/test/transforms/fixtures/insert-fragment/start-second-block/output.yaml new file mode 100644 index 000000000..e111fd668 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/start-second-block/output.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: fragmentanother diff --git a/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/fragment.yaml b/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/fragment.yaml new file mode 100644 index 000000000..3466f52fd --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/fragment.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: list-item + nodes: + - kind: text + ranges: + - text: fragment diff --git a/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/index.js b/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/index.js new file mode 100644 index 000000000..2fe0f3c5f --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/index.js @@ -0,0 +1,41 @@ + +import assert from 'assert' +import path from 'path' +import readMetadata from 'read-metadata' +import { Raw } from '../../../../..' + +export default function (state) { + const file = path.resolve(__dirname, 'fragment.yaml') + const raw = readMetadata.sync(file) + const fragment = Raw.deserialize(raw).document + + const { document, selection } = state + const texts = document.getTexts() + const first = texts.first() + const last = texts.last() + const fragLast = fragment.getTexts().last() + const range = selection.merge({ + anchorKey: first.key, + anchorOffset: 2, + focusKey: last.key, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(range) + .insertFragment(fragment) + .apply() + + assert.deepEqual( + next.selection.toJS(), + range.merge({ + anchorKey: first.key, + anchorOffset: range.anchorOffset + fragLast.length, + focusKey: first.key, + focusOffset: range.focusOffset + fragLast.length + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/input.yaml b/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/input.yaml new file mode 100644 index 000000000..4960c06f9 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/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/insert-fragment/with-delete-across-blocks/output.yaml b/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/output.yaml new file mode 100644 index 000000000..40ab49522 --- /dev/null +++ b/test/transforms/fixtures/insert-fragment/with-delete-across-blocks/output.yaml @@ -0,0 +1,8 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + ranges: + - text: wofragmentother