diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-after/index.js b/test/transforms/fixtures/by-key/remove-text-by-key/selection-after/index.js new file mode 100644 index 000000000..996827711 --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-after/index.js @@ -0,0 +1,31 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const firstText = texts.first() + + const nextSelection = selection.merge({ + anchorKey: firstText.key, + focusKey: firstText.key, + anchorOffset: 2, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(nextSelection) + .removeTextByKey(firstText.key, 0, 1) + .apply() + + assert.deepEqual( + next.selection.toJS(), + nextSelection.merge({ + anchorOffset: 1, + focusOffset: 1 + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-after/input.yaml b/test/transforms/fixtures/by-key/remove-text-by-key/selection-after/input.yaml new file mode 100644 index 000000000..98adb1781 --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-after/input.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: hello diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-after/output.yaml b/test/transforms/fixtures/by-key/remove-text-by-key/selection-after/output.yaml new file mode 100644 index 000000000..d82d81f13 --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-after/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: ello diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-before/index.js b/test/transforms/fixtures/by-key/remove-text-by-key/selection-before/index.js new file mode 100644 index 000000000..beeddb3a7 --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-before/index.js @@ -0,0 +1,31 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const firstText = texts.first() + + const nextSelection = selection.merge({ + anchorKey: firstText.key, + focusKey: firstText.key, + anchorOffset: 2, + focusOffset: 2 + }) + + const next = state + .transform() + .moveTo(nextSelection) + .removeTextByKey(firstText.key, 3, 1) + .apply() + + assert.deepEqual( + next.selection.toJS(), + nextSelection.merge({ + anchorOffset: 2, + focusOffset: 2 + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-before/input.yaml b/test/transforms/fixtures/by-key/remove-text-by-key/selection-before/input.yaml new file mode 100644 index 000000000..98adb1781 --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-before/input.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: hello diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-before/output.yaml b/test/transforms/fixtures/by-key/remove-text-by-key/selection-before/output.yaml new file mode 100644 index 000000000..bac33813a --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-before/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: helo diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-start/index.js b/test/transforms/fixtures/by-key/remove-text-by-key/selection-start/index.js new file mode 100644 index 000000000..aa51524ee --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-start/index.js @@ -0,0 +1,31 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const firstText = texts.first() + + const nextSelection = selection.merge({ + anchorKey: firstText.key, + focusKey: firstText.key, + anchorOffset: 3, + focusOffset: 3 + }) + + const next = state + .transform() + .moveTo(nextSelection) + .removeTextByKey(firstText.key, 2, 1) + .apply() + + assert.deepEqual( + next.selection.toJS(), + nextSelection.merge({ + anchorOffset: 2, + focusOffset: 2 + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-start/input.yaml b/test/transforms/fixtures/by-key/remove-text-by-key/selection-start/input.yaml new file mode 100644 index 000000000..98adb1781 --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-start/input.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: hello diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-start/output.yaml b/test/transforms/fixtures/by-key/remove-text-by-key/selection-start/output.yaml new file mode 100644 index 000000000..bac33813a --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-start/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: helo diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-wrap/index.js b/test/transforms/fixtures/by-key/remove-text-by-key/selection-wrap/index.js new file mode 100644 index 000000000..29398de14 --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-wrap/index.js @@ -0,0 +1,31 @@ + +import assert from 'assert' + +export default function (state) { + const { document, selection } = state + const texts = document.getTexts() + const firstText = texts.first() + + const nextSelection = selection.merge({ + anchorKey: firstText.key, + focusKey: firstText.key, + anchorOffset: 1, + focusOffset: 5 + }) + + const next = state + .transform() + .moveTo(nextSelection) + .removeTextByKey(firstText.key, 2, 1) + .apply() + + assert.deepEqual( + next.selection.toJS(), + nextSelection.merge({ + anchorOffset: 1, + focusOffset: 4 + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-wrap/input.yaml b/test/transforms/fixtures/by-key/remove-text-by-key/selection-wrap/input.yaml new file mode 100644 index 000000000..98adb1781 --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-wrap/input.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: hello diff --git a/test/transforms/fixtures/by-key/remove-text-by-key/selection-wrap/output.yaml b/test/transforms/fixtures/by-key/remove-text-by-key/selection-wrap/output.yaml new file mode 100644 index 000000000..bac33813a --- /dev/null +++ b/test/transforms/fixtures/by-key/remove-text-by-key/selection-wrap/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: helo