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:
committed by
GitHub
parent
a79e11c74e
commit
f45058ec31
@@ -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 },
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
|
28
packages/slate/test/transforms/setPoint/offset.js
Normal file
28
packages/slate/test/transforms/setPoint/offset.js
Normal 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>
|
||||
)
|
Reference in New Issue
Block a user