forked from mathquill/mathquill
-
Notifications
You must be signed in to change notification settings - Fork 0
Mouse Events
Han Wei edited this page Jun 11, 2012
·
3 revisions
The following was last updated for v0.2, the current master
branch of MathQuill. Much will (hopefully) change in v0.3.
(This document assumes knowledge of at least the v0.2 Architecture Overview and Events sections.)
-
mousedown
is the only one permanently bound to the HTML DOM (it's bound to the root element, to whom it is delegated whenever it fires on descendant HTML elements, which should each belong to some descendant math node)- on
mousedown
, we bindmousemove
/up
handlers- we bind them to
document
because while dragging to select, we want to track the mouse wherever it goes, even off the editable or off the page
- we bind them to
- on
- drag-to-select/click algorithm:
-
Cursor::seek()
moves the cursor as close to where a mouse event happened as possible - on
mousedown
,- focus the hidden textarea (just like dragging on a real textarea would focus it)
- hack: make the cursor not blink while mouse held down by setting
cursor.blink = $.noop
-
Cursor::seek()
to where themousedown
happened - drop an "anticursor" where the
mousedown
happened, i.e. save a closured object marking where themousedown
happened - for static math, prepend the temporary hidden textarea, so that while there is math being selected, its LaTeX can be put in the textarea and selected (see Keyboard and Clipboard Events)
- bind
mousemove
andmouseup
handlers todocument
- HACK:
stopPropagation()
, so if this is an\editable
, the containing root math element won't also try to select stuff with its own cursor -
preventDefault()
lest afterwards focus be transferred to the root span
- on
mousemove
,-
Cursor::seek()
to wherever the mouse moved to - select from the anticursor to the cursor, if there's a nonzero selection
- if there's no selection,
Cursor::seek()
showed the cursor, and inmousedown
blink was disabled, so while the mouse is held down in one place, the cursor is shown unblinkingly
- if there's no selection,
-
stopPropagation()
andpreventDefault()
to try to prevent the browser from doing a real selection of the HTML page
-
- on
mouseup
,- hack: reset
cursor.blink
to it's original value as an anonymous function to toggle thevisibility
of the cursor, and then for editables, if there's no selection, callcursor.show()
again, which will redosetInterval(cursor.blink, 500)
- for static math, if there's no selection, detach the temporary hidden textarea because we're done with it
- unbind
mousemove
andmouseup
handlers -
stopPropagation()
andpreventDefault()
to try to prevent the browser from doing a real selection of the HTML page
- hack: reset
-