ChangeCursor Event on MultiSelec

335 views
Skip to first unread message

Vasileios Triglianos

unread,
Dec 5, 2013, 7:27:33 PM12/5/13
to ace-d...@googlegroups.com
Hello everyone,

Is there a way to track cursor position on multi-select mode?

 When a user selects multiple positions in the text the "changeCursor" and "changeSelection" event fire properly. However when he/she starts typing these events do not fire at all. Only document 'change' fires but this doesn't report correct cursor position (looks like the cursor update happens asynchronously).

Thank you!

Harutyun Amirjanyan

unread,
Dec 6, 2013, 10:40:11 AM12/6/13
to ace-d...@googlegroups.com
Hi

When typing in multiselect mode, ace switches to using virtual
selection, and updates real selection only after all cursors are
updated.
Could you show how do you want to use this event?

Thanks

Vasileios Triglianos

unread,
Dec 6, 2013, 11:34:19 AM12/6/13
to ace-d...@googlegroups.com
Hello Harutyun, 

Thank you for your help :-)

So what I want is to synchronize cursors between multiple collaborators. For each collaborator I do something like this

var lang = ace.require("ace/lib/lang") 
this.syncCursor = lang.delayedCall(this._changeCursor) 
var self = this;

this._editor().document.getSelection().on("changeCursor", function(){
   self.syncCursor.delay(50);
});

the changeCursor function looks like this:

_changeCursor: function () {

  var selection = this._editor().document.getSelection();
  var cursors = [];

  if (selection.inMultiSelectMode) {
    cursors = selection.getAllRanges().map(function(range){return range.cursor;})
  } else {
    cursors.push(selection.getCursor())
  }
 
//share cursors with the rest goes here....
}

My main problem is that the' changeCursor' doesn't fire on multiselect when the user is typing. One solution I have found is to add a document 'change' event and do this inside the handler function for the 'change' event.

if ( this._editor().document.multiSelect.inMultiSelectMode){
   this.syncCursor.delay(10);
}

But it seems better if I could just do it with a 'changeCursor' event

Thanx again!

Harutyun Amirjanyan

unread,
Dec 6, 2013, 2:39:05 PM12/6/13
to ace-d...@googlegroups.com
This appears to be a bug in changeCursor event
use editor.on("changeSelection",) instead,
likely changeCursor and changeSelection will be merged in the next version

Vasileios Triglianos

unread,
Dec 6, 2013, 4:01:04 PM12/6/13
to ace-d...@googlegroups.com
This worked perfectly!

Thank you very much for your help :-)

Vasileios Triglianos

unread,
Dec 6, 2013, 6:14:26 PM12/6/13
to ace-d...@googlegroups.com
Sorry, one more thing:

When we are on multi-select mode and the user clicks Esc, then we go back to singleSelection mode but there's no event for that. I thought of doing something like this:

var HashHandler = ace.require("ace/keyboard/hash_handler").HashHandler
var h = new HashHandler([{
  name: "updateCursors",
  bindKey: "esc",
  descr: "Update cursors after esc key in multiline mode",
  exec: function(editor){
    console.log(editor)
   }
}])

this._editor().editor.keyBinding.addKeyboardHandler(h)

But this only responds when I am on single selection mode. Seems like only the one defined in lib/ace/commands/multi_select_commands.js is called while on multi-selection mode. How can I call both of them? Or at least handle an "Esc" key event and at the same time maintain Ace's normal behaviour?

Harutyun Amirjanyan

unread,
Dec 7, 2013, 3:03:55 AM12/7/13
to ace-d...@googlegroups.com
use
editor.selection.on("singleSelect", ...)
but i'll update changeSelection event to fire in this case too, since
this is a problem in cloud9 as well

Vasileios Triglianos

unread,
Dec 7, 2013, 6:16:15 AM12/7/13
to ace-d...@googlegroups.com
Roger that! thanx a lot again!
Reply all
Reply to author
Forward
0 new messages