1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-29 18:09:49 +02:00

Avoid mutating the selection in Transforms.setPoint (#3541)

Since Immer freezes the selection, we will get a TypeError if we try to mutate
the selection. Also, there's no need to mutate it directly in
Transforms.setPoint.
This commit is contained in:
Andreas Geffen Lundahl
2020-03-09 01:51:02 +01:00
committed by GitHub
parent a79e11c74e
commit f45058ec31
2 changed files with 31 additions and 6 deletions

View File

@@ -157,13 +157,10 @@ export const SelectionTransforms = {
const { anchor, focus } = selection
const point = edge === 'anchor' ? anchor : focus
const newPoint = Object.assign(point, props)
if (edge === 'anchor') {
Transforms.setSelection(editor, { anchor: newPoint })
} else {
Transforms.setSelection(editor, { focus: newPoint })
}
Transforms.setSelection(editor, {
[edge === 'anchor' ? 'anchor' : 'focus']: { ...point, ...props },
})
},
/**

View File

@@ -0,0 +1,28 @@
/** @jsx jsx */
import { Editor, Transforms } from 'slate'
import { jsx } from '../..'
export const run = editor => {
Transforms.move(editor)
Transforms.setPoint(editor, { offset: 0 }, { edge: 'focus' })
}
export const input = (
<editor>
<block>
f<cursor />
oo
</block>
</editor>
)
export const output = (
<editor>
<block>
<focus />
fo
<anchor />o
</block>
</editor>
)