From 70b64dc8f10199658ac09bfef141b56187498652 Mon Sep 17 00:00:00 2001 From: Jacob Carpenter Date: Thu, 17 Nov 2022 08:21:37 -0800 Subject: [PATCH] Update `isHistory` to match new interface. (#5197) * Update `isHistory` to match new interface. This change merely preserves the original functionality and does not add verification of Batch's new `selectionBefore` property. * Add changeset. --- .changeset/real-badgers-pull.md | 5 +++++ packages/slate-history/src/history.ts | 6 ++++-- packages/slate-history/test/index.js | 10 ++++++++- .../test/isHistory/after-edit.js | 18 ++++++++++++++++ .../test/isHistory/after-redo.js | 21 +++++++++++++++++++ .../test/isHistory/after-undo.js | 20 ++++++++++++++++++ .../test/isHistory/before-edit.js | 14 +++++++++++++ 7 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 .changeset/real-badgers-pull.md create mode 100644 packages/slate-history/test/isHistory/after-edit.js create mode 100644 packages/slate-history/test/isHistory/after-redo.js create mode 100644 packages/slate-history/test/isHistory/after-undo.js create mode 100644 packages/slate-history/test/isHistory/before-edit.js diff --git a/.changeset/real-badgers-pull.md b/.changeset/real-badgers-pull.md new file mode 100644 index 0000000000..23f4a567c7 --- /dev/null +++ b/.changeset/real-badgers-pull.md @@ -0,0 +1,5 @@ +--- +'slate-history': patch +--- + +Fix isHistory check. diff --git a/packages/slate-history/src/history.ts b/packages/slate-history/src/history.ts index 476bf19032..9a43e209c3 100644 --- a/packages/slate-history/src/history.ts +++ b/packages/slate-history/src/history.ts @@ -27,8 +27,10 @@ export const History = { isPlainObject(value) && Array.isArray(value.redos) && Array.isArray(value.undos) && - (value.redos.length === 0 || Operation.isOperationList(value.redos[0])) && - (value.undos.length === 0 || Operation.isOperationList(value.undos[0])) + (value.redos.length === 0 || + Operation.isOperationList(value.redos[0].operations)) && + (value.undos.length === 0 || + Operation.isOperationList(value.undos[0].operations)) ) }, } diff --git a/packages/slate-history/test/index.js b/packages/slate-history/test/index.js index 2aab12adbf..bb8d16c55f 100644 --- a/packages/slate-history/test/index.js +++ b/packages/slate-history/test/index.js @@ -1,7 +1,7 @@ import assert from 'assert' import { fixtures } from '../../../support/fixtures' import { createHyperscript } from 'slate-hyperscript' -import { withHistory } from '..' +import { History, withHistory } from '..' describe('slate-history', () => { fixtures(__dirname, 'undo', ({ module }) => { @@ -12,6 +12,14 @@ describe('slate-history', () => { assert.deepEqual(editor.children, output.children) assert.deepEqual(editor.selection, output.selection) }) + + fixtures(__dirname, 'isHistory', ({ module }) => { + const { input, run, output } = module + const editor = withTest(withHistory(input)) + run(editor) + const result = History.isHistory(editor.history) + assert.strictEqual(result, output) + }) }) export const jsx = createHyperscript({ diff --git a/packages/slate-history/test/isHistory/after-edit.js b/packages/slate-history/test/isHistory/after-edit.js new file mode 100644 index 0000000000..76042d696b --- /dev/null +++ b/packages/slate-history/test/isHistory/after-edit.js @@ -0,0 +1,18 @@ +/** @jsx jsx */ + +import { Transforms } from 'slate' +import { jsx } from '..' + +export const input = ( + + + Initial text + + +) + +export const run = editor => { + Transforms.insertText(editor, 'additional text') +} + +export const output = true diff --git a/packages/slate-history/test/isHistory/after-redo.js b/packages/slate-history/test/isHistory/after-redo.js new file mode 100644 index 0000000000..5c26ceab87 --- /dev/null +++ b/packages/slate-history/test/isHistory/after-redo.js @@ -0,0 +1,21 @@ +/** @jsx jsx */ + +import { Transforms } from 'slate' +import { jsx } from '..' + +export const input = ( + + + Initial text + + +) + +export const run = editor => { + Transforms.insertText(editor, 'additional text') + + editor.undo() + editor.redo() +} + +export const output = true diff --git a/packages/slate-history/test/isHistory/after-undo.js b/packages/slate-history/test/isHistory/after-undo.js new file mode 100644 index 0000000000..904a614f81 --- /dev/null +++ b/packages/slate-history/test/isHistory/after-undo.js @@ -0,0 +1,20 @@ +/** @jsx jsx */ + +import { Transforms } from 'slate' +import { jsx } from '..' + +export const input = ( + + + Initial text + + +) + +export const run = editor => { + Transforms.insertText(editor, 'additional text') + + editor.undo() +} + +export const output = true diff --git a/packages/slate-history/test/isHistory/before-edit.js b/packages/slate-history/test/isHistory/before-edit.js new file mode 100644 index 0000000000..fc424ce8d1 --- /dev/null +++ b/packages/slate-history/test/isHistory/before-edit.js @@ -0,0 +1,14 @@ +/** @jsx jsx */ +import { jsx } from '..' + +export const input = ( + + + Initial text + + +) + +export const run = () => {} + +export const output = true