title: How do I write a WYSIWYG editor?
body: <p>I would like to program a WYSIWYG editor for HTML.  I'm looking for a high level approach, which I will eventually be implementing in C++.</p>
  
  <p>My initial approach is to create a hierarchy of classes which extend a common base class (node).  So object "body" would contain object "p" which would contain object "b" which would contain some text.</p>
  
  <pre><code>class node {
      node *parent;
      vector&lt;node&gt; children;
  
      string name;
      map&lt;string,string&gt; attributes;
      string text;
  
      virtual void render(const rect &amp;rect, const point &amp;offset) = 0;
      virtual void onEvent(const event &amp;e);
  }
  </code></pre>
  
  <p>The main engine would call something like body.render(screen, point(0, 0)), which would recursively render its children.</p>
  
  <p>The cursor would be represented by a pointer into the object hierarchy, and each node would have its own internal cursor state, and would respond to keyboard events when it is the selected node.</p>
  
  <p>For example, if the user hits the left-arrow, and the "p" node is selected, the "p" node's reaction to the keypress might be to change the current node to the parent of "p".</p>
  
  <p>Abstractly, it seems like this could work, the closest thing I can find to what I'm looking for is <a href="http://code.google.com/p/sigil/" rel="nofollow">Sigil</a>, which at first glance seems pretty intimidating to study (main.cpp is 70k).</p>
  
  <p>Before I go down this road, I was wondering if anyone had a simpler approach, or can see any pitfalls with this method.</p>