parent
2a4d64b074
commit
4efc8db60e
@ -0,0 +1,35 @@
|
||||
import { toJS } from '../utils'
|
||||
|
||||
const setSelection = (doc, op, { id, selection, annotationType }) => {
|
||||
if (!doc.cursors) {
|
||||
doc.cursors = {}
|
||||
}
|
||||
|
||||
const operation = op.toJS()
|
||||
|
||||
if (!doc.cursors[id]) {
|
||||
doc.cursors[id] = {
|
||||
key: id,
|
||||
type: annotationType,
|
||||
data: {}
|
||||
}
|
||||
}
|
||||
|
||||
const cursor = doc.cursors[id]
|
||||
const { focus, anchor } = operation.newProperties
|
||||
|
||||
if (focus) cursor.focus = focus
|
||||
if (anchor) cursor.anchor = anchor
|
||||
|
||||
const cursorPath = (anchor && anchor.path) || (focus && focus.path)
|
||||
|
||||
if (cursorPath) cursor.data.cursorPath = toJS(cursorPath)
|
||||
|
||||
cursor.data.isBackward = selection.isBackward
|
||||
|
||||
return doc
|
||||
}
|
||||
|
||||
export default {
|
||||
set_selection: setSelection
|
||||
}
|
Loading…
Reference in new issue