Skip to content

Commit

Permalink
Update isHistory to match new interface. (ianstormtaylor#5197)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jacobcarpenter authored Nov 17, 2022
1 parent e139c11 commit 70b64dc
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-badgers-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-history': patch
---

Fix isHistory check.
6 changes: 4 additions & 2 deletions packages/slate-history/src/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
},
}
10 changes: 9 additions & 1 deletion packages/slate-history/test/index.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand All @@ -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({
Expand Down
18 changes: 18 additions & 0 deletions packages/slate-history/test/isHistory/after-edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @jsx jsx */

import { Transforms } from 'slate'
import { jsx } from '..'

export const input = (
<editor>
<block>
Initial text <cursor />
</block>
</editor>
)

export const run = editor => {
Transforms.insertText(editor, 'additional text')
}

export const output = true
21 changes: 21 additions & 0 deletions packages/slate-history/test/isHistory/after-redo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/** @jsx jsx */

import { Transforms } from 'slate'
import { jsx } from '..'

export const input = (
<editor>
<block>
Initial text <cursor />
</block>
</editor>
)

export const run = editor => {
Transforms.insertText(editor, 'additional text')

editor.undo()
editor.redo()
}

export const output = true
20 changes: 20 additions & 0 deletions packages/slate-history/test/isHistory/after-undo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** @jsx jsx */

import { Transforms } from 'slate'
import { jsx } from '..'

export const input = (
<editor>
<block>
Initial text <cursor />
</block>
</editor>
)

export const run = editor => {
Transforms.insertText(editor, 'additional text')

editor.undo()
}

export const output = true
14 changes: 14 additions & 0 deletions packages/slate-history/test/isHistory/before-edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @jsx jsx */
import { jsx } from '..'

export const input = (
<editor>
<block>
Initial text <cursor />
</block>
</editor>
)

export const run = () => {}

export const output = true

0 comments on commit 70b64dc

Please sign in to comment.