mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-24 16:02:55 +02:00
Do not store focus/blur in history (#3616)
This commit is contained in:
committed by
GitHub
parent
c20855ff52
commit
42d99af6fa
@@ -49,16 +49,7 @@ export const withHistory = <T extends Editor>(editor: T) => {
|
||||
const inverseOps = batch.map(Operation.inverse).reverse()
|
||||
|
||||
for (const op of inverseOps) {
|
||||
// If the final operation is deselecting the editor, skip it. This is
|
||||
if (
|
||||
op === inverseOps[inverseOps.length - 1] &&
|
||||
op.type === 'set_selection' &&
|
||||
op.newProperties == null
|
||||
) {
|
||||
continue
|
||||
} else {
|
||||
e.apply(op)
|
||||
}
|
||||
e.apply(op)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -155,7 +146,10 @@ const shouldMerge = (op: Operation, prev: Operation | undefined): boolean => {
|
||||
*/
|
||||
|
||||
const shouldSave = (op: Operation, prev: Operation | undefined): boolean => {
|
||||
if (op.type === 'set_selection' && op.newProperties == null) {
|
||||
if (
|
||||
op.type === 'set_selection' &&
|
||||
(op.properties == null || op.newProperties == null)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,49 @@
|
||||
/** @jsx jsx */
|
||||
|
||||
import assert from 'assert'
|
||||
import { Transforms, Editor } from 'slate'
|
||||
import { jsx } from '../..'
|
||||
|
||||
export const run = editor => {
|
||||
// focus at the end
|
||||
Transforms.select(editor, {
|
||||
anchor: { path: [0, 0], offset: 5 },
|
||||
focus: { path: [0, 0], offset: 5 },
|
||||
})
|
||||
// select all
|
||||
Transforms.select(editor, {
|
||||
anchor: { path: [0, 0], offset: 5 },
|
||||
focus: { path: [0, 0], offset: 0 },
|
||||
})
|
||||
// remove
|
||||
Editor.deleteFragment(editor)
|
||||
// blur
|
||||
Transforms.deselect(editor)
|
||||
// focus back
|
||||
Transforms.select(editor, {
|
||||
anchor: { path: [0, 0], offset: 0 },
|
||||
focus: { path: [0, 0], offset: 0 },
|
||||
})
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block>Hello</block>
|
||||
</editor>
|
||||
)
|
||||
|
||||
export const output = {
|
||||
children: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
text: 'Hello',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
selection: {
|
||||
anchor: { path: [0, 0], offset: 5 },
|
||||
focus: { path: [0, 0], offset: 5 },
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user