Skip to content

Commit 70b64dc

Browse files
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.
1 parent e139c11 commit 70b64dc

File tree

7 files changed

+91
-3
lines changed

7 files changed

+91
-3
lines changed

.changeset/real-badgers-pull.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'slate-history': patch
3+
---
4+
5+
Fix isHistory check.

packages/slate-history/src/history.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ export const History = {
2727
isPlainObject(value) &&
2828
Array.isArray(value.redos) &&
2929
Array.isArray(value.undos) &&
30-
(value.redos.length === 0 || Operation.isOperationList(value.redos[0])) &&
31-
(value.undos.length === 0 || Operation.isOperationList(value.undos[0]))
30+
(value.redos.length === 0 ||
31+
Operation.isOperationList(value.redos[0].operations)) &&
32+
(value.undos.length === 0 ||
33+
Operation.isOperationList(value.undos[0].operations))
3234
)
3335
},
3436
}

packages/slate-history/test/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'assert'
22
import { fixtures } from '../../../support/fixtures'
33
import { createHyperscript } from 'slate-hyperscript'
4-
import { withHistory } from '..'
4+
import { History, withHistory } from '..'
55

66
describe('slate-history', () => {
77
fixtures(__dirname, 'undo', ({ module }) => {
@@ -12,6 +12,14 @@ describe('slate-history', () => {
1212
assert.deepEqual(editor.children, output.children)
1313
assert.deepEqual(editor.selection, output.selection)
1414
})
15+
16+
fixtures(__dirname, 'isHistory', ({ module }) => {
17+
const { input, run, output } = module
18+
const editor = withTest(withHistory(input))
19+
run(editor)
20+
const result = History.isHistory(editor.history)
21+
assert.strictEqual(result, output)
22+
})
1523
})
1624

1725
export const jsx = createHyperscript({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @jsx jsx */
2+
3+
import { Transforms } from 'slate'
4+
import { jsx } from '..'
5+
6+
export const input = (
7+
<editor>
8+
<block>
9+
Initial text <cursor />
10+
</block>
11+
</editor>
12+
)
13+
14+
export const run = editor => {
15+
Transforms.insertText(editor, 'additional text')
16+
}
17+
18+
export const output = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** @jsx jsx */
2+
3+
import { Transforms } from 'slate'
4+
import { jsx } from '..'
5+
6+
export const input = (
7+
<editor>
8+
<block>
9+
Initial text <cursor />
10+
</block>
11+
</editor>
12+
)
13+
14+
export const run = editor => {
15+
Transforms.insertText(editor, 'additional text')
16+
17+
editor.undo()
18+
editor.redo()
19+
}
20+
21+
export const output = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** @jsx jsx */
2+
3+
import { Transforms } from 'slate'
4+
import { jsx } from '..'
5+
6+
export const input = (
7+
<editor>
8+
<block>
9+
Initial text <cursor />
10+
</block>
11+
</editor>
12+
)
13+
14+
export const run = editor => {
15+
Transforms.insertText(editor, 'additional text')
16+
17+
editor.undo()
18+
}
19+
20+
export const output = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @jsx jsx */
2+
import { jsx } from '..'
3+
4+
export const input = (
5+
<editor>
6+
<block>
7+
Initial text <cursor />
8+
</block>
9+
</editor>
10+
)
11+
12+
export const run = () => {}
13+
14+
export const output = true

0 commit comments

Comments
 (0)