This was an informal presentation about my exploratory efforts to implement a pure JS rich-text editor on the web (https://github.com/unframework/motepad)
• product technical lead at Myplanet • backend, frontend, server automation • first fulltime gig was at TMX in 2002 • passionate about: ◦ UX ◦ lean enterprise ◦ empathy-driven engineering
italics, font sizing, etc • contentEditable to the rescue! • how it works: ◦ put contenteditable=”true” on an element ◦ done! or is it? • problematic ◦ browser bugs, content model issues, extensibility ◦ https://medium.com/medium-eng/why- contenteditable-is-terrible-122d8a40e480
the Google Docs team needed custom layout/formatting power ◦ used pure JS/DOM • wanted simple rich textbox, not full MS Word ◦ string with arbitrary meta-data (including links/etc) ◦ example: Twitter/FB social text (mentions, tags, etc) • seemed like a nifty challenge! :)
• start laying out, row by row • for each token: ◦ compute width in pixels (put in a span, read width) ◦ see if line would overflow (start a new line then) ◦ add the token • easy
of events into the editor ◦ insert, move cursor (left/right), move line (up/down), home/end ◦ mouseUp/mouseDown, mouseMove • editor state ◦ text + attribute data ◦ normal mode: cursor position index ◦ dragging/selection mode: selection range indices
plain/Word/HTML ◦ input pattern detection for hashtags/@-mentions/etc ◦ performance (cache all the things) ◦ keyboard behaviour nitpicks (OS-specific, even!) ◦ things we take for granted! • deep dive = excellent learning experience