Fine, I’ll build my own text editor! – David Bushell – Web Dev (UK)

🔥 Read this trending post from Hacker News 📖

📂 **Category**:

💡 **What You’ll Learn**:

and make it editable with a contenteditable attribute. That attribute has a plaintext-only value that is perfect for code. All content remains within a single text node.

<div
  contenteditable="plaintext-only"
  autocapitalize="off"
  autocorrect="off"
  spellcheck="false"
  translate="no">
  
div>

Attributes like spellcheck must be disabled to avoid input latency spikes. Want to guess how many days it took me to discover that fix? Days!

Using contenteditable gives native text selection and undo history etc. So much accessibility goodness is wired up for free by the browser.

The Selection API provides metrics I use to continue rendering a custom text cursor. ::selection is available so I can style that too. I’ve set the native caret-color invisible, which is probably a no-no.

The contenteditable technique is promising but I’ve noticed strange performance issues beyond a certain character count. Chromium browsers perform worse than WebKit and whatever Firefox is now but it’s unpredictable.

Textarea

Instead of plaintext contenteditable would a simple