mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 09:43:58 +02:00
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.
This commit is contained in:
5
.changeset/real-badgers-pull.md
Normal file
5
.changeset/real-badgers-pull.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-history': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix isHistory check.
|
@@ -27,8 +27,10 @@ export const History = {
|
|||||||
isPlainObject(value) &&
|
isPlainObject(value) &&
|
||||||
Array.isArray(value.redos) &&
|
Array.isArray(value.redos) &&
|
||||||
Array.isArray(value.undos) &&
|
Array.isArray(value.undos) &&
|
||||||
(value.redos.length === 0 || Operation.isOperationList(value.redos[0])) &&
|
(value.redos.length === 0 ||
|
||||||
(value.undos.length === 0 || Operation.isOperationList(value.undos[0]))
|
Operation.isOperationList(value.redos[0].operations)) &&
|
||||||
|
(value.undos.length === 0 ||
|
||||||
|
Operation.isOperationList(value.undos[0].operations))
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import assert from 'assert'
|
import assert from 'assert'
|
||||||
import { fixtures } from '../../../support/fixtures'
|
import { fixtures } from '../../../support/fixtures'
|
||||||
import { createHyperscript } from 'slate-hyperscript'
|
import { createHyperscript } from 'slate-hyperscript'
|
||||||
import { withHistory } from '..'
|
import { History, withHistory } from '..'
|
||||||
|
|
||||||
describe('slate-history', () => {
|
describe('slate-history', () => {
|
||||||
fixtures(__dirname, 'undo', ({ module }) => {
|
fixtures(__dirname, 'undo', ({ module }) => {
|
||||||
@@ -12,6 +12,14 @@ describe('slate-history', () => {
|
|||||||
assert.deepEqual(editor.children, output.children)
|
assert.deepEqual(editor.children, output.children)
|
||||||
assert.deepEqual(editor.selection, output.selection)
|
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({
|
export const jsx = createHyperscript({
|
||||||
|
18
packages/slate-history/test/isHistory/after-edit.js
Normal file
18
packages/slate-history/test/isHistory/after-edit.js
Normal file
@@ -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
packages/slate-history/test/isHistory/after-redo.js
Normal file
21
packages/slate-history/test/isHistory/after-redo.js
Normal file
@@ -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
packages/slate-history/test/isHistory/after-undo.js
Normal file
20
packages/slate-history/test/isHistory/after-undo.js
Normal file
@@ -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
packages/slate-history/test/isHistory/before-edit.js
Normal file
14
packages/slate-history/test/isHistory/before-edit.js
Normal file
@@ -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
|
Reference in New Issue
Block a user