regarding ymacs caret

6 views
Skip to first unread message

Jason Wang

unread,
Apr 14, 2010, 12:41:26 AM4/14/10
to Ymacs - AJAX code editor
Hi,

i was trying to understand how the code is structured. i read the pdf
regarding your style of programming, but i still couldn't figure out
how you did your caret at this point.

Basically, when i click on a character anywhere, you can detect which
character precisely i've clicked and move the caret there. How did you
detect which character i clicked? Where did you handle to the event?

thank you very much for any pointers!

Jason

Mihai Călin Bazon

unread,
Apr 14, 2010, 2:29:37 AM4/14/10
to ym...@googlegroups.com
Hi Jason,

It's one of the tricky parts. :-)  But the algorithm is quite simple — look in ymacs-frame.js, function "_on_mouseDown".

1. determine the (x, y) of the click in pixels relative to the editor (that is, point (0, 0) is the top-left corner of the editor area).  This is done by ev.computePos(element)  (DynarchLIB function).

2. translate coordinates into (line, column) with coordinatesToRowCol(x, y) (look for this function in Ymacs_Frame).

This second function is the tricky one.  It defines two helper functions, findLine and findCol.  They are recursive and work the same, although for column is a bit more work.  They start from the middle, and search that line/column which is closest to the mouse click.

Another helper is the coordinates(line, column) function (also in Ymacs_Frame) which returns the (x, y) in pixels of a certain character in the buffer.  To accomplish this it inserts an empty SPAN tag at that position and then looks up its coordinates.

Inserting the SPAN is a story in itself, and it's implemented in the insertInText function (again, in ymacs-frame.js).

Hope this helps.

Cheers,
-Mihai


--
www.ymacs.com - AJAX code editor

To unsubscribe, reply using "remove me" as the subject.



--
Mihai Bazon,
http://mihai.bazon.net/blog

Jason Wang

unread,
Apr 14, 2010, 4:08:31 PM4/14/10
to Ymacs - AJAX code editor
Hey Mihai,

I am trying to look through the DlEvent library, but i can't figure
out what the DOM argument (where your D and P are) is. As well, for
clarification, the difference between event and eventproxy is that
event is for native events in javascript and eventproxy is for user
defined events?

Another question, i noticed that in the docs it says for EventProxy
you need to call callHooks to pass in parameters and such. Is the ev
in _on_mouseDown(ev) an instance of DlEvents?

Thank you very much for all your help!

Jason

On Apr 14, 2:29 am, Mihai Călin Bazon <mihai.ba...@gmail.com> wrote:
> Hi Jason,
>

> It's one of the tricky parts. :-) But the algorithm is quite simple -- look

> >www.ymacs.com- AJAX code editor

Reply all
Reply to author
Forward
0 new messages