diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/before-selection/index.js b/test/transforms/fixtures/by-key/insert-text-by-key/selection-after/index.js similarity index 100% rename from test/transforms/fixtures/by-key/insert-text-by-key/before-selection/index.js rename to test/transforms/fixtures/by-key/insert-text-by-key/selection-after/index.js diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/input.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-after/input.yaml similarity index 100% rename from test/transforms/fixtures/by-key/insert-text-by-key/after-selection/input.yaml rename to test/transforms/fixtures/by-key/insert-text-by-key/selection-after/input.yaml diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/before-selection/output.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-after/output.yaml similarity index 100% rename from test/transforms/fixtures/by-key/insert-text-by-key/before-selection/output.yaml rename to test/transforms/fixtures/by-key/insert-text-by-key/selection-after/output.yaml diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/index.js b/test/transforms/fixtures/by-key/insert-text-by-key/selection-before/index.js similarity index 100% rename from test/transforms/fixtures/by-key/insert-text-by-key/after-selection/index.js rename to test/transforms/fixtures/by-key/insert-text-by-key/selection-before/index.js diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/before-selection/input.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-before/input.yaml similarity index 100% rename from test/transforms/fixtures/by-key/insert-text-by-key/before-selection/input.yaml rename to test/transforms/fixtures/by-key/insert-text-by-key/selection-before/input.yaml diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/after-selection/output.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-before/output.yaml similarity index 100% rename from test/transforms/fixtures/by-key/insert-text-by-key/after-selection/output.yaml rename to test/transforms/fixtures/by-key/insert-text-by-key/selection-before/output.yaml diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/selection-end/index.js b/test/transforms/fixtures/by-key/insert-text-by-key/selection-end/index.js new file mode 100644 index 000000000..8e4310bc4 --- /dev/null +++ b/test/transforms/fixtures/by-key/insert-text-by-key/selection-end/index.js @@ -0,0 +1,28 @@ + +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: 4 + }) + + const next = state + .transform() + .moveTo(nextSelection) + .insertTextByKey(firstText.key, 4, 'XX') + .apply() + + assert.deepEqual( + next.selection.toJS(), + nextSelection.toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/in-selection/input.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-end/input.yaml similarity index 100% rename from test/transforms/fixtures/by-key/insert-text-by-key/in-selection/input.yaml rename to test/transforms/fixtures/by-key/insert-text-by-key/selection-end/input.yaml diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/selection-end/output.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-end/output.yaml new file mode 100644 index 000000000..607d42d0c --- /dev/null +++ b/test/transforms/fixtures/by-key/insert-text-by-key/selection-end/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: hellXXo diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/selection-start/index.js b/test/transforms/fixtures/by-key/insert-text-by-key/selection-start/index.js new file mode 100644 index 000000000..7faa90b8e --- /dev/null +++ b/test/transforms/fixtures/by-key/insert-text-by-key/selection-start/index.js @@ -0,0 +1,30 @@ + +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: 4 + }) + + const next = state + .transform() + .moveTo(nextSelection) + .insertTextByKey(firstText.key, 2, 'XX') + .apply() + + assert.deepEqual( + next.selection.toJS(), + nextSelection.merge({ + focusOffset: 6 + }).toJS() + ) + + return next +} diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/selection-start/input.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-start/input.yaml new file mode 100644 index 000000000..98adb1781 --- /dev/null +++ b/test/transforms/fixtures/by-key/insert-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/insert-text-by-key/selection-start/output.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-start/output.yaml new file mode 100644 index 000000000..5395838b8 --- /dev/null +++ b/test/transforms/fixtures/by-key/insert-text-by-key/selection-start/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: heXXllo diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/in-selection/index.js b/test/transforms/fixtures/by-key/insert-text-by-key/selection-wrap/index.js similarity index 100% rename from test/transforms/fixtures/by-key/insert-text-by-key/in-selection/index.js rename to test/transforms/fixtures/by-key/insert-text-by-key/selection-wrap/index.js diff --git a/test/transforms/fixtures/by-key/insert-text-by-key/selection-wrap/input.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-wrap/input.yaml new file mode 100644 index 000000000..98adb1781 --- /dev/null +++ b/test/transforms/fixtures/by-key/insert-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/insert-text-by-key/in-selection/output.yaml b/test/transforms/fixtures/by-key/insert-text-by-key/selection-wrap/output.yaml similarity index 100% rename from test/transforms/fixtures/by-key/insert-text-by-key/in-selection/output.yaml rename to test/transforms/fixtures/by-key/insert-text-by-key/selection-wrap/output.yaml