designMode和contentEditable这条贼船

今天在玩Code Mirror 2,读到这条 internal:

CodeMirror 1 was heavily reliant on designMode or contentEditable (depending on the browser). Neither of these are well specified (HTML5 tries to specify their basics), and, more importantly, they tend to be one of the more obscure and buggy areas of browser functionality—CodeMirror, by using this functionality in a non-typical way, was constantly running up against browser bugs. WebKit wouldn't show an empty line at the end of the document, and in some releases would suddenly get unbearably slow. Firefox would show the cursor in the wrong place. Internet Explorer would insist on linkifying everything that looked like a URL or email address, a behaviour that can't be turned off. Some bugs I managed to work around (which was often a frustrating, painful process), others, such as the Firefox cursor placement, I gave up on, and had to tell user after user that they were known problems, but not something I could help.

幸好我没上这条贼船啊。想起了沈大仙在《程序员的 100 种境界》中一句经典的话:

IE 的这个 BUG 只要用 IE 另外的一个 BUG 就可以解决了

现在做HTML的rich WYSIWYG editor一般就这么几条路:

  1. iframe
  2. textarea
  3. div contentEditable
  4. place a micro textarea at cursor

Google Docs(此link目前挂了)也用了一个和4比较类似的YD技巧。

Comments