feat: success garbage cursor

This commit is contained in:
cudr
2019-10-12 12:19:06 +03:00
parent 4efc8db60e
commit ad2780b936
3 changed files with 34 additions and 9 deletions

View File

@@ -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
const cursorStart = cursor && cursor.anchor && cursor.anchor.offset
const cursorEnd = cursor && cursor.focus && cursor.focus.offset
if (!selectionOps.size && selection.start.offset !== cursorOffset) {
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)
)