Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ErnWong/ed89119520a4e81d942dced5c0febd52 to your computer and use it in GitHub Desktop.
Save ErnWong/ed89119520a4e81d942dced5c0febd52 to your computer and use it in GitHub Desktop.
  • Selection has a cursor
  • Selection has an origin
  • Selection, when dragging, can snap to certain points to select various granularity, such as whole words, whole sentences, etc.
    • Granularity can be specified by a custom getSnapPoints function or something similar.
      • Or infer granularity from single/double/triple click?
    • Preset getSnapPoints functions for common mediums such as text can be provided
    • Selection starts off without snapping, and snapping is only activated once it passes the first snap point.
  • Dragging the selection backwards could still snap, but if the backward motion is slow enough, the selection snapping will be disabled until selection is dragged to the right past a snapping point.
  • When snapping is activated, both the cursor and origin is snapped in opposite directions to extend the selection. Is this a desired user feature?
  • When selection cursor is brought back close to the origin, between the origin and the first snapping point, then snapping is disabled for that dragging session. The original origin point is also restored.
  • What happens if this is a real-time collaboration environment, where someone edits the text you are selecting with snapping on? Does the snapping change?

Perhaps the snapping points are the same as the course selection movement keyboard commands?

  • Control+drag will add range.
    • Overlapping ranges - should they be merged? No
    • Should each range have its own cursor position and origin position? Yes, so that they can be extended using shortcut keys.
  • Alt+drag will select in block mode. Can be combined with control.
    • Block mode selection behaves as multiple subranges, one subrange per line, each with their own cursor and origin positions.
    • Should selection snap into snap points in this case?
  • Shift+drag will extend selection
  • Shift+movement will extend selection by the movement for all subranges.
    • E.g. control+movement will typically be a more coarse-grained movement such as skipping over words. Control+shift+right will move the cursor positions for each subrange by one word to the right.

Selection State:

  • List of Selection Ranges

Selection Range:

  • Origin
  • Cursor

Selection Drag State:

  • Original Origin - may not be the final origin after snapping is applied, but is required so the original origin can be restored if snapping is cancelled
  • Current Cursor
  • Is Snapping Disabled For Session
  • Is Snapping Active

Selection Drag Derived Values:

  • Current Origin - derived from original origin as the first snapping point to encounter in the text when going in the direction opposite to the direction of the cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment