Skip to content

Commit

Permalink
Do not store focus/blur in history (#3616)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist authored Mar 31, 2021
1 parent c20855f commit 42d99af
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
16 changes: 5 additions & 11 deletions packages/slate-history/src/with-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
})
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 },
},
}

0 comments on commit 42d99af

Please sign in to comment.