Missing initial cursor when starting with an empty doc #6

Closed
benbro opened this Issue Jan 7, 2013 · 2 comments

Projects

None yet

2 participants

@benbro

When the initial doc is an empty string it tries to transform a cursor which doesn't exists and fail.

  • Start the server with an empty doc.
  • Connect with client A.
  • Connect with client B.
  • Write "a" with client A.
  • Backspace with client B
  • Client A gets an error: TypeError: this.cursorAfter is undefined @ http://localhost:3000/ot.js:1271 It's coming from the undo manager which didn't have this.cursorBefore which is now this.cursorAfter.

I can add a cursor when creating the EditorClient which solves this issue.
The problem with this is that when client A is typing he'll see client's B cursor chasing him at the end of the doc which is distracting.

The temp workaround:
function EditorClient (revision, clients, serverAdapter, editorAdapter) {
Client.call(this, revision);
this.serverAdapter = serverAdapter;
this.editorAdapter = editorAdapter;
this.undoManager = new UndoManager();
// initialize the cursor
this.cursor = new Cursor(0, 0);

Is there a better fix?

Thanks

@timjb
Operational-Transformation member

I can't reproduce this anymore. But I think that I might have already fixed this bug incidentally with cc55f31. The way this commit solves the issue is by triggering the cursorActivity event in CodeMirrorAdapter when the CodeMirror instance gets focused (before you type the A). This event will cause the EditorClient to save the current cursor position. Therefore the cursor position will be initialised when you type 'a'. Can you confirm this?

@benbro

Looks good. Thanks

@benbro benbro closed this Jan 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment