Skip to content
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 bind mousemove/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
  • 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 the mousedown happened
      • drop an "anticursor" where the mousedown happened, i.e. save a closured object marking where the mousedown 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 and mouseup handlers to document
      • 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 in mousedown blink was disabled, so while the mouse is held down in one place, the cursor is shown unblinkingly
      • stopPropagation() and preventDefault() 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 the visibility of the cursor, and then for editables, if there's no selection, call cursor.show() again, which will redo setInterval(cursor.blink, 500)
      • for static math, if there's no selection, detach the temporary hidden textarea because we're done with it
      • unbind mousemove and mouseup handlers
      • stopPropagation() and preventDefault() to try to prevent the browser from doing a real selection of the HTML page
Clone this wiki locally