Text Selection Event listening

794 views
Skip to first unread message

bne

unread,
Mar 11, 2014, 2:41:37 AM3/11/14
to ace-d...@googlegroups.com
Hello all,

I plan to store the different text selections that user makes.

I was looking at the "changeCursor" and "changeSelection" events, but since they are fired each time the user's selection changes, I am finding it hard to differentiate between one text selection and the other.

Been thinking of what I could do.  Ideally, I would have events like "startSelection" and "endSelection", and could then just get the initial row-column and the end row-column and that would represent one selection.  But I know it is not that simple.

Then I was thinking about having some sort of delay that would prevent users from making selections immediately right after the other so I could "differentiate" them into separate selections.

Is what I am asking possible or am I outside the scope of ACE editor?

Thanks!

Harutyun Amirjanyan

unread,
Mar 11, 2014, 7:05:04 AM3/11/14
to ace-d...@googlegroups.com
Hi

could you describe in more detail when you expect "startSelection"
and "endSelection"to be fired and how should they work with multiple
selections

I am planning to add undo selection to ace and for that most likely
will use afterExec event
see https://github.com/ajaxorg/ace/blob/master/lib/ace/editor.js#L178

bne

unread,
Mar 11, 2014, 4:40:50 PM3/11/14
to ace-d...@googlegroups.com
Hey Harutyun,

I don't actually expect "startSelection" and "endSelection" to be implemented, I was just using the idea of them to explain my situation.  It may turn out I might not even need them.

What I really need is when a user makes a text selection, I just need the first and last Row/column sets.  For example, what I am doing now is:

editor.getSession().on('changeCursor', function() {
    // Store the Row/column values
});

Although when a user clicks and drags the text selection over the text they want, this event fires each time they drag over a character.  So for example, what is stored might be something like:
Row : Column -
0 : 0
0 : 1
0 : 2
0 : 3
0 : 4
0 : 5

But in reality, all I want is 0 : 0 and 0 : 5.

I would also need to make sure that when a user makes a different selection, it is stored as its own selection.

Is there currently any way to handle this?  I guess what I am really looking for is something like "mouseClickStartSelect" and "MouseReleaseEndSelect".

Would detecting by mouse click and release events cause issues with Ace?

Harutyun Amirjanyan

unread,
Mar 16, 2014, 4:46:10 PM3/16/14
to ace-d...@googlegroups.com
Is this only about mouse selection or any selection?
If it's only about mouse

editor.on("mousedown", function() {
// Store the Row/column values
})

editor.getSession().on('changeCursor', function() {
if (editor.$mouseHandler.isMousePressed)
// remove last stored values
// Store the Row/column values
});

should work, but storing only row:column won't work with multiple selections
Reply all
Reply to author
Forward
0 new messages