feat: success garbage cursor

pull/2/head
cudr 5 years ago
parent 4efc8db60e
commit ad2780b936

@ -124,6 +124,7 @@ class Connection {
socket.leave(id)
this.garbageCursor(socket.nsp.name, id)
this.garbageNsp()
}
@ -137,6 +138,20 @@ class Connection {
})
}
garbageCursor = (nsp, id) => {
const doc = this.docSet.getDoc(nsp)
if (!doc.cursors) return
const change = Automerge.change(
doc,
`remove cursor ${id}`,
(d: any) => delete d.cursors[id]
)
this.docSet.setDoc(nsp, change)
}
removeDoc = async nsp => {
const doc = this.docSet.getDoc(nsp)

@ -21,7 +21,9 @@ const setSelection = (doc, op, { id, selection, annotationType }) => {
if (focus) cursor.focus = focus
if (anchor) cursor.anchor = anchor
const cursorPath = (anchor && anchor.path) || (focus && focus.path)
const cursorPath = cursor.data.isBackward
? anchor && anchor.path
: focus && focus.path
if (cursorPath) cursor.data.cursorPath = toJS(cursorPath)

@ -115,9 +115,7 @@ class Connection {
if (!doc) return
const selectionOps = operations.filter(op => op.type === 'set_selection')
console.log('hasSelectionOps', selectionOps.size)
operations = operations.filter(op => op.type !== 'set_selection')
const { value } = this.editor
@ -130,12 +128,24 @@ class Connection {
}
const cursor = doc.cursors[meta.id]
const cursorOffset = cursor && cursor.anchor && cursor.anchor.offset
if (!selectionOps.size && selection.start.offset !== cursorOffset) {
const cursorStart = cursor && cursor.anchor && cursor.anchor.offset
const cursorEnd = cursor && cursor.focus && cursor.focus.offset
console.log('cursor!!', cursorStart, cursorEnd)
console.log('selection!!', selection.start.offset, selection.end.offset)
if (
selection.start.offset !== cursorStart ||
selection.end.offset !== cursorEnd
) {
console.log(
'!!!!!! append selection op!!!',
selection.start.toJS(),
selection.end.toJS()
)
const opData = {
type: 'set_selection',
properties: {},
properties: cursor || {},
newProperties: {
anchor: selection.start,
focus: selection.end
@ -147,8 +157,6 @@ class Connection {
operations = operations.push(op)
}
console.log('operations', operations.toJSON())
const changed = Automerge.change(doc, message, (d: any) =>
applySlateOps(d, operations, meta)
)

Loading…
Cancel
Save