<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Piotrek Koszuliński on Medium]]></title>
        <description><![CDATA[Stories by Piotrek Koszuliński on Medium]]></description>
        <link>https://medium.com/@reinmarpl?source=rss-e0cc07d50af5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eTpp1WMpoogzN8gYIt1XCw.jpeg</url>
            <title>Stories by Piotrek Koszuliński on Medium</title>
            <link>https://medium.com/@reinmarpl?source=rss-e0cc07d50af5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:22:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@reinmarpl/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The art of debugging — or how it took me 3 years to fix my PC]]></title>
            <link>https://medium.com/content-uneditable/the-art-of-debugging-or-how-it-took-me-3-years-to-fix-my-pc-23a9f7ec1426?source=rss-e0cc07d50af5------2</link>
            <guid isPermaLink="false">https://medium.com/p/23a9f7ec1426</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[crime]]></category>
            <dc:creator><![CDATA[Piotrek Koszuliński]]></dc:creator>
            <pubDate>Tue, 20 Nov 2018 16:30:42 GMT</pubDate>
            <atom:updated>2018-11-21T08:59:44.378Z</atom:updated>
            <content:encoded><![CDATA[<h3>The art of debugging — or how it took me 3 years to fix my PC</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4bm36rfUlcwhJZ6rpH_1wQ.jpeg" /><figcaption>Author: <a href="https://www.flickr.com/photos/eleanorleonne/">Eleanor Leonne Bennett</a></figcaption></figure><p><em>Disclaimer: I’m not a hardware engineer. This is not a story about CPU soldering or whatever hardware engineers find sexy. But it is a story.</em></p><p>I’ve recently been trying to resurrect my old PC. I haven’t used it at all over the last 3 years and moved twice in the meantime (including moving from Denmark to Poland).</p><p>Obviously, I started from plugging it in but it would not start. Nothing would happen when I pressed the start button.</p><p>That brought back the memories. I already had problems with this PC not wanting to start in the past. Every couple of weeks it wouldn’t react to pressing the power button. I also had problems with disks freezing to death while the PC was working (you could move your mouse, use apps that you loaded previously, but you couldn’t open anything new).</p><p>In the past, while I was still using it, I suspected a power supply damage. I replaced it. I changed the disks. RAM. Graphics card (because I wanted to play The Witcher and it was a good reason for buying a more powerful GC :D). Nothing helped.</p><p>When investigating this problem I noticed that opening the case, unplugging disks and plugging them back would sometimes help. There was that green LED (SB_PWR) next to the SATA sockets on the motherboard. It was off right after I had experienced an issue. But it would turn on either when I did the replugging or just waited some time. It was a mystery.</p><p>So, here I was 3 years later and trying to resurrect this PC. It was a pretty good PC a couple of years ago so, obviously, I didn’t want to just throw it away. Plus, I abandoned my Ubuntu distro with all my old data there so I needed to access those disks anyway.</p><p>I opened the case and realised that the SB_PWR LED is off. <em>“Yes… that again. So it must be a motherboard’s fault. I replaced all the other parts and that didn’t help. I need to look for a new one.”</em></p><p>I left the PC and moved on to other things. A couple of days later, I look at it and yes, the green light is ON! It’s alive!</p><p>I booted it. Everything worked fine, although after I restarted it, I needed to repeat the old replugging of SATA drives. Just like in the past. However, if it had already booted, it worked fine, so I started backing up my old data (<a href="https://www.youtube.com/watch?v=kddqINA1vOA">“Oh, Ubuntu… you’re my favourite Linux-based operating system”</a>). In order to do that, I needed to plug in an external USB disk.</p><p>The PC was laying flat on my desk, so the easiest way to plug an external drive was to use the back panel, the one directly on the motherboard. When I touched the USB port with a plug, fireworks! The PC switched off, the LED turned dead.</p><p><strong>Did I just burn it? And what the heck was that?!</strong></p><p>Before I answer that, one more flashback. About 5 years ago I noticed that my MacBook Air’s charger (the metal plug) was slightly electrified. Back then I lived in Denmark where for some reason power sockets have no grounding. I thought, back then, that my charger has some sort of short circuit (you know how those Apple’s cables tended to look after a year of use) and the charge stays in the plug (which is aluminium) because the whole thing is not grounded. Changing the charger to a new one didn’t help, though, so I turned my attention to the power strip. It turned out that plugging the charger to some other socket was helping, so I thought that the old power strip (which was grounded, because I bought it in Poland) was at fault and I bought a new one (which didn’t have grounding bolts at all because we were in Denmark). That helped. No more shocks when using the MacBook charger.</p><p>Back to the fireworks. Guess which power strip I was using now? Yes, the one without the grounding. Guess what happened when I checked the PC’s case with an electrical tester? Yes, it was electrified. But why? That’s a new power strip I was using. The one which made the MacBook problems disappear!</p><p>That’s true, but it wasn’t the power strip’s fault. It wasn’t the old MacBook charger’s fault either. The problems that I had 4–5 years ago didn’t go away. They just focused solely on my PC… because I switched to a non-grounded power strip during my time in Denmark. As a result, my PC stopped affecting other appliances that I have plugged to the same power strip.</p><p>But how did it happen that my PC’s case was electrified? Cause I’m a lazy moron and I did a mistake when assembling a new PC 5 years ago. <a href="https://imgur.com/cWVhWJv">Here’s a link to a photo which explains what I did.</a></p><p>Those aluminium strips were touching the USB power pins. That made my PC’s case electrified. I’m guessing that they were touching just so slightly that the connection could change based on the temperature, me moving the PC’s case (to open it and replug the SATA drives), etc. Me touching the PC’s case (while doing the replugging) might’ve also affected what was happening (I was grounding it with my hands). Also, since the touching point was so delicate, it wasn’t a big “leak”. Presumably, it sometimes made the PC’s power supply lose just enough power (or made the voltage unstable) so it wasn’t able to properly power the USB ports and… the SATA drives. Hence, the green LED switching off.</p><p>Why did I see fireworks when I tried to plug an external USB drive there? Because I touched the aluminium plate (and the strips) and made the contact area larger. Why didn’t I discover it for a couple of years while using this PC? Because I never used those rear USB ports in normal situations.</p><p>While “debugging” these two issues (PC, MacBook charger) I replaced my disks, an old power supply, RAM, the old power strip, my old MacBook charger. I thought I resolved some of the problems, but it turned out that I just isolated the real problem that I had. It’s funny in how many ways the problem was manifested and what kind of dirty fixes I discovered. It’s also interesting how the environment (Danish non-grounded power sockets and later on a non-grounded power strip) affected the problem.</p><p>If I were using a grounded power strip and a grounded power socket my guess is I would either burn the power supply or an <a href="https://en.wikipedia.org/wiki/Residual-current_device">RCCB</a> would indicate that I’ve got a big problem (though the “leak” was so small that perhaps nothing would’ve happened anyway). If I replaced the old grounded power strip with a new, grounded one I would realise that the same problems still occur, so the fault must be somewhere else (not the charger, not the power strip, so there is a big chance that I’d look at my PC which, at that time, was working quite fine).</p><p>This story has many analogies to debugging software (and most likely, pretty much any other more complex mechanism).</p><ul><li><strong>A single issue can manifest itself in many ways, in many places.</strong> There’s a great chance that if you focus on the visible part of the problem, you won’t notice the real cause.</li><li><strong>When debugging an issue, you need to consider how changes in the environment affect your issue at hand.</strong> A problem may not occur locally or under a specific load, locale, etc. Taking the right conclusions from “this only happens when X” can often save you many hours.</li><li><strong>The most tricky issues to debug are those that seem to occur randomly.</strong> Finding patterns lets you tame them a bit, but may be really hard if you don’t know the scope of the problem.</li><li><strong>You can become more proficient in debugging</strong> (or <a href="https://www.reddit.com/r/javascript/comments/9jlml6/how_do_you_improve_your_problem_solving_skills/e6sg0g2/">“problem-solving” in general</a>) by gaining more knowledge about the field and experience in resolving similar problems. If I were a hardware engineer, this would, most likely, be an easy-peasy for me.</li><li><strong>You may need tools and some spare parts.</strong> I wasn’t able to properly test what was happening with my PC which made validating my various hypotheses more of a guessing game.</li><li><strong>Sometimes the fix requires just 1 changed character in the code.</strong> It might take you a couple days if not months (or years :D) to find it, though.</li><li><strong>You need to understand why your patch fixes the problem.</strong> Sometimes developers are able to get rid of an error by tweaking the line in which it occurs. However, I tend to reject such patches if their authors can’t explain the whys and hows. Changing a line from which the error is thrown is often not the right fix if you can’t tell how you got to this state in the first place.</li><li><strong>Fixing harder bugs may require connecting many seemingly unrelated dots.</strong> Since evidence of the bug can appear only at certain conditions, it may happen that you’ll notice them rarely, over a longer period of time. Keep your eyes open and look for patterns.</li><li><strong>Debugging really complex issues is an art.</strong></li><li><strong>You can’t just google some issues.</strong></li><li><strong>Sometimes you just need to be lucky.</strong></li></ul><p>Good luck!</p><p>PS. I’d like to use this occasion to thank my Dad who made me curious about electronics and software when I was a kid. And to Olek who corrected this article because I apparently still don’t know much about electronics :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23a9f7ec1426" width="1" height="1" alt=""><hr><p><a href="https://medium.com/content-uneditable/the-art-of-debugging-or-how-it-took-me-3-years-to-fix-my-pc-23a9f7ec1426">The art of debugging — or how it took me 3 years to fix my PC</a> was originally published in <a href="https://medium.com/content-uneditable">Content Uneditable</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why We Chose a Multirepo Architecture for CKEditor 5]]></title>
            <link>https://medium.com/content-uneditable/why-we-chose-a-multirepo-architecture-for-ckeditor-5-54c7e50af1f5?source=rss-e0cc07d50af5------2</link>
            <guid isPermaLink="false">https://medium.com/p/54c7e50af1f5</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Piotrek Koszuliński]]></dc:creator>
            <pubDate>Tue, 07 Jun 2016 11:42:35 GMT</pubDate>
            <atom:updated>2016-06-07T12:32:35.349Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgQF4ARBZ-SQDmaSFIpqzA.jpeg" /><figcaption>A pile of watch cogwheels by <a href="https://www.flickr.com/photos/oppen2009/">Abbey Swan</a></figcaption></figure><p>Last week I tweeted about the lack of a centralised GitHub statistic for <a href="https://medium.com/content-uneditable/ckeditor-5-the-future-of-rich-text-editing-2b9300f9df2c#.swq0s06yu">CKEditor 5</a> which is a result of the multirepo architecture that we currently have:</p><h3>Piotrek Koszuliński on Twitter</h3><p>The thing that I miss most in #CKEditor5&#39;s multi-repo architecture is that there&#39;s no single contributors graph any more :D</p><p>In a response, Jan Dudek pointed out that “notable projects stay with monolithic architecture”.</p><h3>Jan Dudek on Twitter</h3><p>@reinmarpl Interesting that you chose to split. Some notable projects stay with monolithic repos. Where do you see the biggest advantages?</p><p>I failed to fit it into a tweet, so here’s a short article.</p><h3>Thumbs Up for Monorepo</h3><p>To answer why we’ve made a choice to keep CKEditor 5 code in multiple repositories I should perhaps first explain what problems that brings. Or rather — what are the advantages of keeping things in a single repository.</p><p>What Jan Dudek might have in mind is summarized in the “<a href="https://github.com/babel/babel/blob/master/doc/design/monorepo.md">Why is Babel a monorepo?</a>” article. As its authors point out, the topic was discussed dozens of times and the main pros of a monorepo architecture are:</p><ul><li>Single lint, build, test and release process.</li><li>Easy to coordinate changes across modules.</li><li>Single place to report issues.</li><li>Easier to setup a development environment.</li><li>Tests across modules are ran together which finds bugs that touch multiple modules easier.</li></ul><p>It’s all true. We’ve been there and seen these things. However, most of the arguments (like linting, building, releasing, setting up a development environment, testing) are just a matter of creating and utilizing the right tools. We’ve <a href="https://github.com/ckeditor/ckeditor5/wiki/Development-Environment">done that</a>, although I admit that it required some time because, as <a href="https://twitter.com/thejameskyle">James Kyle</a> writes, the platform (surprisingly) doesn’t support such an environment:</p><h3>James Kyle on Twitter</h3><p>It&#39;s amazing to me that for a community that loves millions of tiny little modules the DX of working across many node modules is so awful</p><p>The second part of the arguments for a monorepo setup is related to maintenance — reporting issues and coordinating changes across packages. We understand that the community won’t know in which CKEditor repository certain bugs should be reported. Therefore, it’s clear for us that there must be a <a href="http://github.com/ckeditor/ckeditor5">central repository</a> where uncategorised and vague bugs will be reported. They can be moved to the proper repositories once the real cause or topic is identified. This will require some additional work, but we’ve always done it anyway. Working with a huge and diverse community requires it.</p><h4>NPM</h4><p>This is a topic for a separate article, but I’ll never write one, so here’s an excerpt from it.</p><p>An obvious choice for a packaging system for code kept in all these repositories was of course <a href="https://www.npmjs.com/">npm</a>. It works great (although slooow) in a normal situation when just one or two of your packages are in a development mode and you just need to install their dependencies and keep them <a href="https://docs.npmjs.com/cli/link">npm linked</a>. Unfortunately, in case of CKEditor, we may reach something like 100 or more packages in the future (plus, packages may have dependencies between one other). Imagine now that you want to keep 10 of them in a development version, so whenever one of them changes, that change should also affect all dependent packages. This is where linking fails short, especially that such npm commands like <em>install</em> or <em>update</em> break when encountering it. We’ve seen all kind of issues and random behaviours which we couldn’t even report. Additionally, it’s super inconvenient because you need to explicitly tell npm to install <em>globally</em> kept dev versions of dependencies in <em>all</em> dependent packages.</p><p>Long story short, we needed to come up with a quite complicated mechanism for updating all these repositories and a builder which can find proper packages in all this mess. This toolset is still young, but it works fine.</p><h3>Why Multirepo Then?</h3><p>Usually we discuss such topics in issues in the <a href="https://github.com/ckeditor/ckeditor5-design/issues">CKEditor 5 design</a> repository, however, this time we haven’t opened one, because it was something that we’ve decided before even starting the project. I guess that it’s high time that we explain our way of thinking.</p><p>There are obvious issues when dealing with dozens of repositories and npm packages. We can’t deny that. It slows us down a bit and may be confusing at times. It also required spending a significant amount of time on the toolset, but I still think that (in our case) the cost was worth it.</p><h4>It’s a Framework to Be Used by the Community</h4><p>CKEditor 5 is an editing library that’s going to be used by the community to develop hundreds of features. Therefore, it’s also a framework in which these features can be created in a standardised and controlled way.</p><p>We (the core team) are going to create the most popular packages, but the community will create even more of them. We can keep our features together with the framework in one repository, but the community can’t. Other developers will need to work on their packages in their own repositories. That was the case in CKEditor 4 — the plugin architecture was in place, but development and maintenance of 3rd party add-ons was horrible because the entire workflow was designed around a <a href="http://github.com/ckeditor/ckeditor-dev">single repository</a>.</p><p>By using the same setup as the community we wanted to ensure that we’ll create proper tools for working with the project.</p><h4>Packages Are Independent Projects</h4><p>This is controversial and it’s not black and white. CKEditor 5 is made of a core, editing engine, UI library and features. It’s a big project with multiple layers of architecture. We often tend to see such code bases as monoliths. An insignificant change in one module affects couple of other ones, but it’s not a problem, because it’s all a single repo.</p><p>We’ve been there with CKEditor 4 and we’re there with CKEditor 5. It happens that a single change (especially in a lower level of your application) requires changes in a couple of other places. However, it’s often also a result of bad architecture caused by too tight coupling between modules.<br>Splitting your project into multiple repositories won’t magically fix your architecture, but it’ll force you to think about all the pieces separately. The more times you have to deal with a single change in one package which required changes in 10 others, the more you’ll think how to avoid such situations. And from what I can tell, it really helped us. Waterfall situations still happen, but the overall architecture is a lot better.</p><h4>Because a Single Repository Doesn’t Solve All Problems With npm</h4><p>I had a moment of doubt when I came to <a href="https://twitter.com/fredck">Fred</a> and said: “I’ve got enough of this, let’s merge all the repos. We only care to have multiple npm packages after all, just like Babel does, right?”. But it was then that I understood that all the issues with npm will stay.</p><p>If you have one repository which contains multiple packages, you still have multiple package.json files and all those packages have dependencies between each other. So you’re in exactly the same situation in which we are — you need to install all of them using symlinks. I’ve seen somewhere in <a href="https://github.com/babel/babel">Babel repository</a> that they have some ugly scripts to do that.</p><p>So the only thing we would gain by merging the repositories (from the development tools perspective) would be getting rid of the need to clone and update all these repositories, which is fairly simple, compared to npm issues.</p><h4>Mind the Granularity</h4><p>Node.js’s community is known for its love for creating npm packages for even the tiniest pieces of code. I bet it’s fun, but at the same time it’s ridiculous if you use such packages, ending up with hundreds of packages in your boilerplate code (seriously, I got a couple hundreds of npm packages installed in a recruitment task that I’ve been reviewing).</p><p>We don’t plan to split CKEditor 5 packages that much. For instance, the <a href="https://github.com/ckeditor/ckeditor5-basic-styles">ckeditor5-basic-styles</a> is going to contain all basic styling commands like bold, italic, underline, etc. Thanks to that, having something like 50.000 LOC (excluding tests), we have only <a href="https://github.com/ckeditor?utf8=%E2%9C%93&amp;query=ckeditor5">15 repositories</a>.</p><h3>It’s Working</h3><p>The number of repositories will grow significantly, but we can’t complain so far. Of course, things are slower (pulling changes to 15 repos or running <em>npm install</em> in newly installed ones takes time) and sometimes we need to touch a couple of repositories at once, but thanks to the development tools that we created (and which we’re going to improve as we go), all these problems are acceptable. At the same time, an inclusive, open platform and its effect on the architecture of the project are a nice return on investment. I believe that, especially in a longer term, we and the community will appreciate it.</p><p>A multirepo architecture is not for everyone though. It will be an overkill for most projects and I’ve heard some painful stories about that. However, taken the love to micro modules, the JavaScript community will need to solve this situation somehow. Who knows, maybe we’ll be able to share our tools one day?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54c7e50af1f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/content-uneditable/why-we-chose-a-multirepo-architecture-for-ckeditor-5-54c7e50af1f5">Why We Chose a Multirepo Architecture for CKEditor 5</a> was originally published in <a href="https://medium.com/content-uneditable">Content Uneditable</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing ContentEditable]]></title>
            <link>https://medium.com/content-uneditable/fixing-contenteditable-1a9a5073c35d?source=rss-e0cc07d50af5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a9a5073c35d</guid>
            <category><![CDATA[standards]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Piotrek Koszuliński]]></dc:creator>
            <pubDate>Fri, 21 Aug 2015 12:31:40 GMT</pubDate>
            <atom:updated>2015-09-18T14:56:20.215Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pWhiJd-AOg_yBf4m_qilrw.jpeg" /><figcaption>Matterhorn. Author: <a href="https://www.flickr.com/photos/malavoda/">malavoda</a></figcaption></figure><p>Working with a system which is driving you mad because of a monstrous library overflowing with quirks is often a great discouragement. How many times did you feel that you should totally drop your project because it’s beyond repair and it’s too much work to implement it from scratch?</p><p>That’s pretty much the situation of contentEditable today. The difference here is that in order to fix it, first you need to convince the entire world that it needs to be fixed. If you succeed, then you still need to find a consensus on every tiny detail with other interested parties. Finally, if the specification is accepted it can be implemented in all browser engines.</p><h3>The History</h3><p><em>(Please correct me if I excavated some of the facts incorrectly.)</em></p><p>ContentEditable was first implemented in Internet Explorer 5.5 back in 2000. 5 years later it was reverse-engineered by <a href="https://annevankesteren.nl/">Anne van Kesteren</a> and around the year 2007 it was implemented in all major engines. In each and every single one of them differently. <a href="https://blog.whatwg.org/the-road-to-html-5-contenteditable">Here you can read more</a> about the history of contentEditable.</p><p>Since 2007 the Web has evolved. We had HTML 5, ECMAScript 5 and 6, CSS 3, countless new APIs and JavaScript frameworks, rounded borders and pastel colors were replaced by flat design and single page websites (there’s a running joke in W3C that when <em>border-radius </em>was finally standardized, we invented flat design). A constant race to implement all the new features and the evergreen browsers bring us all the new goodies faster than we can learn about them.</p><p>What has changed in the contentEditable world during this period? Let’s see… IE9 was the first IE to support modern Selection API, IE11 was a big step forward too, but other browsers were mainly left untouched (except occasional bug fixes which sometimes turned into new bugs).</p><p>We can’t blame anyone, because <strong>contentEditable has no spec</strong>. That doesn’t mean that no one tried to write it. HTML5 might only <a href="https://html.spec.whatwg.org/multipage/interaction.html#editing-2">scratched the surface</a>, but Aryeh Gregor did a <em>great job</em> creating a <a href="https://w3c.github.io/editing/historic-editing-apis.html">real spec for all the HTML Editing APIs</a>. I’m not sure whether it’s complete and what was its exact timeline, but the spec is really detailed and mentions year 2011 here and there. So why didn’t it work? I wasn’t a CKEditor developer back then (I joined shortly after), but as far as I know there might have been two reasons. First, Aryeh was a contractor for Google, so as it ended there was no one who could (or wanted to) continue his work. Second, the spec didn’t convince others, especially editor developers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ieMrmX9-3nVsY6DPzSHZlw.jpeg" /><figcaption>Risk Of Spontaneous Combustion. Author: <a href="https://www.flickr.com/photos/andymag/">Andy Maguire</a></figcaption></figure><p>From a developer’s perspective, the most apparent issues are that each browser implements contentEditable in a completely different way and that it’s a high level API which gives you no helping hand if you want to do something <strong>your way</strong>. If you want to use the bold feature, then you need to accept how it works or reimplement it from scratch. If you want the <em>Enter</em> key to insert paragraphs instead of <em>&lt;div&gt;</em>, then you need to accept how it works or reimplement the whole feature. If you want to change the way the caret responds to user actions, then again — hack it or accept it. Given the inconsistency of the APIs that you’d need to use, it’s a nightmare.</p><p>While Aryeh’s spec could have solved the first problem (inconsistent behavior) it did very little with the second problem — opening the browser to developers. Advanced rich-text editors already avoid <em>document.execCommand()</em> because the existing commands are useless and had to be reimplemented. Furthermore, every rich-text editor is different and every use case is different, so rich-text editors must be extensible and configurable. Therefore, even if Aryeh’s spec was perfect and the browsers followed it precisely, the authors of rich-text editors would still need to implement all the features themselves.</p><p>The third problem with contentEditable is its scope. If you’re familiar with my article <a href="https://medium.com/content-uneditable/contenteditable-the-good-the-bad-and-the-ugly-261a38555e9c">“ContentEditable — The Good, The Bad and The Ugly”</a>, then you have the notion of how complex editing can be even when talking about basic features (if you haven’t read it, please do ;). Since contentEditable tries to be a complete WYSIWYG editor itself, with support for all the most important HTML features (lists, tables, links, inline styles, images, etc.) its scope is immense. Even if Aryah succeeded and the spec was complete, there would still be a lot of doubts and discussions. In the end, browser vendors would need to work on aligning their current implementations to the spec.</p><p>Following this path, we come to the last problem. ContentEditable is already widely used and every change made to its implementations would break the existing editors. For some people, this is an argument for killing contentEditable and working on a new, clean solution. For others, this means that we should only commit minimum necessary changes in the current implementation to make it more digestible. Eventually, the technologies of the future will enable rich-text editor developers to build their apps without contentEditable.</p><p>However, both approaches have one major flaw — the time that we would need to wait for their implementation. We do need contentEditable (or a complete replacement of it) because <a href="https://medium.com/content-uneditable/contenteditable-the-good-the-bad-and-the-ugly-261a38555e9c">you can’t just build a real editor based on today’s features</a>.</p><p>There is a third way though.</p><h3>Modular ContentEditable</h3><p>Last year we’ve finally noticed a light at the end of the tunnel. Two lights, actually. First of all, <a href="https://twitter.com/ryosukeniwa">Ryosuke Niwa</a> <a href="https://lists.w3.org/Archives/Public/public-webapps/2014AprJun/0122.html">extracted</a> the <a href="http://w3c.github.io/selection-api/">Selection API</a> from the HTML Editing APIs spec created by Aryeh Gregor. This move allowed working on the selection system more independently from contentEditable.</p><p>The second light was lit by <a href="https://twitter.com/johanneswilm">Johannes Wilm</a> from <a href="http://www.fiduswriter.org/">Fidus Writer</a> and Ben Peters from Microsoft who started pushing forward a new, promising concept, initially called <em>contentEditable=minimal</em>.</p><p>So what’s that <em>contentEditable=minimal</em>? The initial idea was <a href="https://lists.w3.org/Archives/Public/public-webapps/2014AprJun/0296.html">described by Ben Peters</a> as follows:</p><blockquote><em>(…) it makes sense to enable a new, simpler version of contentEditable that provides basic functionality only. For the sake of discussion, call it contentEditable=’minimal’. The functionality provided by the browser under contentEditable=’minimal’ would be as follows:</em></blockquote><blockquote><em>* Caret drawing<br>* Events such as Keyboard , Clipboard, Drag and Drop<br>* Some keyboard input handling- caret movement, typing of characters including Input Method Editor input<br>* Selection drawing and manipulation according to the new Selection API spec</em></blockquote><p>I replied with <a href="https://lists.w3.org/Archives/Public/public-webapps/2014AprJun/0575.html">my initial vision</a>, but it quickly turned out that everyone sees <em>contentEditable=minimal</em> differently. Fortunately, the morale and engagement of various parties were high enough to keep the idea alive. The <a href="http://www.w3.org/wiki/Editing_Taskforce">Editing Task Force</a> was established (see the <a href="https://lists.w3.org/Archives/Public/public-editing-tf/">mailing list</a>, <a href="https://github.com/w3c/editing/issues">bug list</a> and produced <a href="https://w3c.github.io/editing/">documents</a>) and we are actually about to <a href="http://www.w3.org/wiki/Fall_2015_Editing_Taskforce_F2F_meeting">meet in Paris</a> to discuss the current state of affairs and create an action plan to move forward.</p><p>I’d like to take this occasion to thank <a href="https://twitter.com/johanneswilm">Johannes Wilm</a> for his work as the editor of the spec. Without his determination we might’ve given up since our whole energy is often consumed by discussions.</p><h3>The Vision</h3><p><a href="https://lists.w3.org/Archives/Public/public-webapps/2014AprJun/0296.html">Ben Peters’ email</a> triggered countless discussions on how <em>contentEditable=minimal</em> could work. There were some widely accepted concepts, but all in all there was still no agreement about the basics. Because dwelling on every idea that was put forward would make this article awfully long (if I would ever finish it at all), I decided to focus on the current state of things.</p><p><strong>&lt;Disclaimer&gt;<br></strong>The following vision is strictly subjective. It can’t be treated as an official statement of the members of W3C Editing Task Force!<br><strong>&lt;/Disclaimer&gt;</strong></p><h4>ContentEditable=true</h4><p>Let’s start from simple things. There seems to be a general consensus about not touching <em>contentEditable=true</em> and <em>document.execCommand()</em>. They’re too big, too messy, wrong and already widely used. These features are unlikely to become officially deprecated (at least not yet), but their use will be discouraged.</p><p>What’s still a bit unclear is whether the new features which I describe later in this article will be added to <em>contentEditable=true</em> as well (and if yes, then which ones exactly). I hope some of them will be capable of being “backported” — that could, in a relatively short time, improve the situation with contentEditable=true too. But that’s not a priority.</p><h4>Events</h4><p>This is a second topic which is pretty clear — we need browsers to fire more events. Especially those which allow developers to:</p><ul><li>understand the intention of the user,</li><li>override the default behavior of the browser.</li></ul><p>What’s the big deal with events? Today, you can listen to keyboard, mouse, touch and other events but you always need to figure out the meaning of the action. User pressed a key, so perhaps a letter should be inserted. User clicked or touched the screen, so perhaps selection was moved. In general terms, guessing isn’t what developers like to do.</p><p>Furthermore, guessing user’s intention is just the beginning. In many cases you’ll want to alter the default native behavior. Imagine that you want to implement a “track changes” feature. When the user starts typing, the text should be inserted in an <em>&lt;ins&gt;</em> tag and each time something is deleted (either by <em>Delete</em> or <em>Backspace</em> keys, cutting, selecting some text and pressing any key or the <em>Delete</em> option in the native context menu) instead of removing something we would like to wrap it with <em>&lt;del&gt;</em>. With today’s events such as <em>keydown</em> and no ability to manually handle typing or text deletion (again, if you haven’t read <a href="https://medium.com/content-uneditable/contenteditable-the-good-the-bad-and-the-ugly-261a38555e9c">this article</a>, please do) you need to resort to the ugliest possible hacks.</p><p>To tackle these problems the family of events that we often use in our editors like <em>paste, beforepaste </em>(from the <a href="https://w3c.github.io/clipboard-apis/">Clipboard API</a>) or <em>dragstart,</em> <em>drop</em> from the <a href="http://www.w3.org/TR/html51/editing.html#dnd">HTML 5</a> will be extended with:</p><ul><li><em>beforeinput </em>(from <a href="https://w3c.github.io/editing/input-events.html">HTML Editing</a>) — to enable control over input (making changes). This event will be fired with <em>inputType </em>(e.g. <em>‘insertCharacter’</em>, <em>‘replaceText’</em>, <em>‘insertNewLine’</em>) and <em>data</em> (e.g. a letter that should be inserted). It is designed in a way that will cover such editing operations as character composition or spell checking. With a single event you’ll now be able to control all editing operations.</li><li><em>selectionchange, selectionstart</em> and <em>beforeselectionchange</em> (all in the <a href="https://github.com/w3c/selection-api">Selection API</a>) — to enable better control over the selection and caret movements. The <em>beforeselectionchange</em> event will be fired with a property that will tell how the user intends to change the selection (extend it forward, backwards, upwards, jump a whole word, etc.) as well as the proposed selection.</li></ul><p>The best thing about <em>beforeinput </em>and <em>beforeselectionchange </em>is that these events can be cancelled to prevent the default action (if there’s any) or the default action can be changed. These events will also carry useful information like a range that should be affected.</p><p>There’s also one more interesting initiative that touches this subject — <a href="http://www.w3.org/WAI/intro/indieui">Independent User Interface</a> (IndieUI), which exposes meaningful events for various UI–related actions. As far as I can see, text editing isn’t currently covered, but we could imagine a <em>bold</em> event which would be fired when the browser discovers that a user may want to bold a text (in some languages <em>Ctrl+B </em>may not be the usual keystroke for that or the action could be triggered from context menu or a special popup shown on mobile browsers).</p><h4>Selection API</h4><p>It’s crucial for rich-text editor authors that the <a href="https://github.com/w3c/selection-api">Selection API</a> is predictable and complete. There are currently many inconsistencies which seriously impede our work. To name just a few — <a href="https://github.com/w3c/editing/issues/64#issuecomment-131053162">too drastic selection normalization</a>, <a href="https://github.com/w3c/editing/issues/68#issuecomment-131765254">behavior around HTML elements such as &lt;canvas&gt; and &lt;svg&gt;</a>, behavior around non-editable elements. The API also lacks some features — the <a href="https://github.com/w3c/selection-api/issues/37">modify()</a> method that would allow customising caret movements, a <a href="https://github.com/w3c/selection-api/issues/51">way to specify whether the caret should be rendered after or before line break</a> and some other methods which would simplify <a href="https://github.com/w3c/editing/issues/56#issuecomment-131584200">various other tasks</a>. The <a href="https://github.com/w3c/selection-api/issues">list</a> is pretty long and actually goes beyond the Selection API since some extensions for the Range API would also be useful.</p><h4>ContentEditable=events</h4><p>The initial concept of introducing contentEditable=minimal has evolved during the past year. There were proposals to introduce <em>contentEditable=typing</em>, <em>contentEditable=cursor</em> and other modes from which a developer will be able to pick. By using e.g. the “typing” mode, a developer would inform the browser that it should handle text insertion. Similarly, the “cursor” mode would enable native caret movements (yes, there’s something wrong with the name :D).</p><p>While the concept of splitting <em>contentEditable=true</em> into many opt-in modules sounds reasonable, it means that we keep the same (or even higher) complexity as before, because the native behaviour must still be spec-ed and the modes must be orthogonal.</p><p>To reduce the scope, the modules concept was currently limited to <em>contentEditable=events</em> (although other modules may be spec-ed in the future). It’s a much simplified proposal, which at the same time may solve the majority of our problems.</p><p>For me, the whole “editing” can boil down to two types of actions:</p><ul><li>those which affect the content (typing, deleting, formatting, pasting, dragging),</li><li>those which do not affect the content (various ways of changing the selection, rendering of native UI components such as context menus, floating toolbars, spell checker markers).</li></ul><p>As a rich-text editor implementer I would love to control every aspect of editing, but my highest priority is to control the content. I can accept that the caret doesn’t move exactly like I would like it to move in some cases, but I cannot accept if content in my editor gets messed up by the browser.</p><p><em>ContentEditable=events</em> seems to reflect this division. In this mode the browser will handle caret movements and selection changes, while it won’t modify the DOM. This means that you can relatively easily add support for typing (by using the <em>beforeinput</em> event), but you don’t need to <a href="https://github.com/w3c/editing/issues/71">worry about implementing your own selection handler</a> which would be a very tricky job taking the scope into account (mouse, keyboard, touch devices and countless little details like <a href="https://en.wikipedia.org/wiki/Bi-directional_text">BiDi</a>). However, thanks to the <em>beforeselectionchange </em>event<em> </em>I can handle the cases in which I do not agree with the native behavior. This also means that spec-ing caret movements isn’t that crucial and can be done later.</p><p>I hope that we will be able to reach consensus about this proposal, because it seems to be the middle ground between spec-ing everything and brutal reality, in which no one has enough energy to do that.</p><h3>So what’s the ETA?</h3><p>I wish I knew. Next week we’re <a href="https://www.w3.org/wiki/Fall_2015_Editing_Taskforce_F2F_meeting">meeting in Paris</a> to tackle the remaining issues. There’s no mutual agreement yet about some important details such as whether in contentEditable=events the browser should handle caret movements or how selection may be normalized and where it can be displayed. The <em>beforeselectionchange</em> event has been proposed a long time ago, but <a href="https://github.com/w3c/selection-api/issues/56">it hasn’t been added</a> to the Selection API spec either.</p><p>If we agree about these and other matters in Paris, then, as far as I understand, the <a href="https://w3c.github.io/editing/">Editing</a> and <a href="http://w3c.github.io/selection-api/">Selection API</a> specs will be very close to becoming <a href="http://www.w3.org/Consortium/Process/Process-19991111/tr.html#RecsCR">Candidate Recommendations</a>. Given that browser vendors are involved in both specs, this means that we’ll be on the threshold of fixing contentEditable. I can’t predict how quickly the new features will land in browsers, but let’s hope for “soon” :).</p><p>In other words, it seems that this attempt to fix contentEditable will not share the fate of the previous one. Keep your fingers crossed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a9a5073c35d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/content-uneditable/fixing-contenteditable-1a9a5073c35d">Fixing ContentEditable</a> was originally published in <a href="https://medium.com/content-uneditable">Content Uneditable</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ContentEditable — The Good, the Bad and the Ugly]]></title>
            <link>https://medium.com/content-uneditable/contenteditable-the-good-the-bad-and-the-ugly-261a38555e9c?source=rss-e0cc07d50af5------2</link>
            <guid isPermaLink="false">https://medium.com/p/261a38555e9c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[accessibility]]></category>
            <dc:creator><![CDATA[Piotrek Koszuliński]]></dc:creator>
            <pubDate>Thu, 13 Aug 2015 14:04:14 GMT</pubDate>
            <atom:updated>2019-04-02T21:14:46.928Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dr6FyBZoAP-EKF94n-xtiA.jpeg" /><figcaption>Author: <a href="https://www.flickr.com/photos/bortabra/">Göran Ingman</a></figcaption></figure><p>Every once in a while some developer notices that there’s <em>still</em> no <em>perfect</em> WYSIWYG editor for the web on the market and then this happens:</p><h3>Piotrek Koszuliński on Twitter</h3><p>Hey, we just met and this is crazy, but we&#39;ve got few hours so let&#39;s create a new WYSIWYG editor maybe!</p><p>How hard can it be? We’ve got <a href="http://html5demos.com/contenteditable">contentEditable</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand"><em>execCommand()</em></a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/queryCommandState"><em>queryCommandState()</em></a>. Now, let’s just add some toolbar with stylish buttons to enable applying bold and linking the text. We’ll work a bit on typography, use some trendy SVG/font icons for the buttons, add some CSS transitions here and there and we are mostly ready. Right?</p><p>Just a couple of details left… How do I force the <em>bold</em> command to use <em>&lt;strong&gt;</em> instead of <em>&lt;b&gt;</em> (choose whichever you like more, actually) in every browser, force the <em>Enter</em> key to create new paragraphs instead of those ugly <em>&lt;br&gt;</em> or <em>&lt;div&gt;</em> and fix that damn pasting. I don’t want all those inline styles!</p><p>A month and several questions on <a href="http://stackoverflow.com/">StackOverflow</a> later the project is either dead or full of most brutal hacks which seem to work (that’s actually the worst situation — poor end-users). The developer joins the <em>“contentEditable is evil”</em> club and hates WYSIWYG editors even more.</p><p>Those three small details — how the <em>bold</em> command and <em>Enter</em> key work plus cleaning up pasted data are just the tip of the iceberg, but they are already enough to make even a skilled JavaScript developer hate <em>“this entire contentEditable”</em>.</p><p>Let’s consider how the behavior of the <em>bold</em> command can be altered. I’ve seen many approaches from the hacky ones like using mutation observers, through normalisation of HTML when retrieving it from the editor, to a complete (in my opinion, the only real) solution which is reimplementing the <em>execCommand()</em> behavior in JavaScript. But again, this is only the tip of the iceberg.</p><p>If you chose the mutation observers, you may need to deal with preserving selection (as it may be reset when you modify the DOM around it) or with the <a href="http://www.w3.org/wiki/Web_Editing_APIs/UndoManager_Problem_Descriptions">undo manager</a>.</p><p>If you accepted normalisation of the output you’re pretty safe, but I can hardly imagine the same approach to the <em>Enter</em> key support and well… it smells bad.</p><p>If you’re a purist like me, you would perhaps try to implement <em>execCommand()</em> in JavaScript. The algorithm is pretty straightforward — get the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection">selection</a>, get <a href="https://developer.mozilla.org/en-US/docs/Web/API/Selection/getRangeAt">ranges</a> (did I mention that Firefox supports multi-range selections?), do a couple of DOM operations, make selection, implement undo manager (because your changes won’t be recorded by the native one) and you’re safe. Except that:</p><ul><li>You were fired for delaying the project for a few months.</li><li>Your tests don’t pass in any other browser (oh and did I mention that <a href="https://bugs.webkit.org/show_bug.cgi?id=15256">Blink and WebKit</a>’s selection systems are broken? Yes… the bug is 8 years old) and you’re about to implement one of the most ugly hacks you’ll ever see.</li><li>First bug reports start to appear and you start to realise how many more cases your implementation needs to support.</li><li>You still need to implement the <em>Enter</em> key support and do something with the damn pasting.</li><li>You’ve just noticed that you also need to reimplement <em>Backspace</em> and <em>Delete</em> key support in <a href="http://code.google.com/p/chromium/issues/detail?id=226941">Blink</a> and <a href="https://bugs.webkit.org/show_bug.cgi?id=114791">WebKit</a> as these engines love inline styles far more than you do.</li><li>You’ve noticed that some engines return a <em>href</em> attribute with an absolute URL even though you made a link with a relative URL.</li><li>Gosh… we only talked about four most basic features — when will you add support for images?</li><li>Didn’t you know that the selection has a direction?</li></ul><p>Enough. I think I’ve made the point. <a href="https://medium.com/medium-eng/why-contenteditable-is-terrible-122d8a40e480">ContentEditable is terrible</a>. Related APIs and their implementations such as selection, clipboard and drag and drop are incomplete and/or inconsistent and buggy. Range API is complicated and inconvenient. But your fridge isn’t empty yet and now you know what to do.</p><h3>Goodbye, contentEditable</h3><p>The idea is simple. ContentEditable is evil and the Selection API is its evil twin. Avoid them as much as possible. So what’s the plan?</p><ol><li>You need a custom selection system. It must be doable nowadays to get position (represented by a range, but we’ll simplify this in a moment) in the DOM on <em>mousedown</em>/<em>mousemove</em>. You’ll display your custom caret (whoa… you can control its style now) and text selection (it’s a simple <em>&lt;span&gt;</em>).</li><li>You need to handle typing. Let’s listen to the keyboard events and insert given character into the editor.</li><li>You need to handle navigation using the <em>Arrow</em> keys. Left and right seem easy, up and down a bit trickier but if you have point 1, you’ll do this too. Wait, there’s the <em>Alt</em> modifier which makes the <em>Left</em> and <em>Right Arrow</em> keys jump entire words. But of course you’ll look for spaces in the text and that’s it — told you, it’s trivial!</li><li>Then you need to do something with pasting. You see that with the Clipboard API you can listen to the paste event on the document and retrieve the data from the data transfer. You can also use the old <a href="http://docs.ckeditor.com/#!/guide/dev_clipboard-section-paste-bin">paste bin mechanism</a>.</li></ol><p>The world is beautiful again. You’re surrounded by well known APIs or your own code which you can finally control. Say bye to that terrible feeling of being hopeless. You use the Selection API and ranges only for a direct interaction with the browser, but internally you implemented different mechanisms, more appropriate for text editing. No need to work on that ambiguous DOM. Only text, styles, indexes and translation to DOM. Applying bold is now a simple algorithm — add the style to selected letters and your automatic translation will update the DOM.</p><p>The food in the fridge is scarce, so you publish your project on <a href="http://github.com/">GitHub</a>. You start receiving first bug reports, but no worries, no software is perfect from day one.</p><blockquote><strong>How Do I Type Polish Characters?</strong></blockquote><blockquote>When I press <em>Alt+L</em> I expect that ‘ł’ is inserted, but your editor inserts ‘l’.</blockquote><p>Right, let’s see what you can do. You don’t know the keyboard layout, so you can’t simply check for the <em>Alt</em> modifier. Besides, there’re too many languages. OK, there’s <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key"><em>KeyboardEvent.key</em></a> from <a href="https://w3c.github.io/uievents/">DOM level 3</a> but so far it only works in IEs and Firefox. <a href="https://code.google.com/p/chromium/issues/detail?id=263724">Blink will support</a> it soon, too, so you can wait. There’s a high chance that all major browsers will support it within a reasonable time.</p><blockquote><strong>How Do I Type Accents?</strong></blockquote><blockquote>I have a Spanish keyboard layout. When I press ‘`’ and then a letter (e.g. `u`) I expect to first see the ‘tick’ and then letter ‘ù’ in the same place.</blockquote><p>Wait, what? Does he say that two keys are transformed into one letter? That’s crazy… you can handle these special cases somehow (if you can find out what keyboard layout is in use), but let’s hope that there aren’t many languages which work this way.</p><blockquote><strong>How Do I Type Hiragana Characters?</strong></blockquote><blockquote>When I start typing this popup should appear and the word I’m currently typing should be underlined. It’s the so-called composition.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yhycdntbbkwkR0pd6cT8yA.png" /></figure><p>Right, <a href="https://developer.mozilla.org/en-US/docs/Web/Events/compositionstart">composition events</a>. You’re sure you can do something with them (if only the browser would fire them). What’s worse, you find out that the <a href="https://en.wikipedia.org/wiki/Input_method">Input Method Engine</a> works differently in every OS and is often integrated with the OS (e.g. it learns new words and implements smart autocompletion). You’re beginning to feel hopeless once again. But then a brilliant idea comes to your mind — you can use a hidden textarea from which you’ll read the input. If you position it close to the caret you’ll even have the popup. You only lose contextual suggestions. There’s also some work on <a href="http://www.w3.org/TR/ime-api/">opening the IME API</a>. One day you’ll remove all the hacks!</p><blockquote><strong>How Do I Type Using My iPad?</strong></blockquote><blockquote>When I tap the editor, the keyboard does not appear.</blockquote><p>No focus in an editable field = no keyboard. Surely the trick with a hidden textarea will work. Will it? How do you paste now?</p><blockquote><strong>Alt+Left/Right Arrow Should Jump Over One Word</strong></blockquote><blockquote>This text ‘ພາສາຈີນແມ່ນພາສາໜຶ່ງທີ່ເວົ້າໃນປະເທດຈີນ.’ contains many words, but your editor handles it as one word.</blockquote><p>But where are the spaces?!</p><blockquote><strong>Undoing by Shaking Does Not Work on iPhone</strong></blockquote><p>Right, it’s bound to <em>Ctrl+Z</em>. Time to use the accelerometer.</p><blockquote><strong>Keyboard Is Hidden When I Do a Selection on iPhone/iPad</strong></blockquote><p>Right. Focus moves from the hidden textarea to the document…</p><blockquote><strong>Spell Checking Doesn’t Work</strong></blockquote><p>The horror! The horror!</p><blockquote><strong>I Can’t Use Your Editor with a Keyboard and a Screen Reader</strong></blockquote><blockquote>Your editor isn’t accessible. Normally when I tab into an editor, my screen reader notifies me about it. Then, when I navigate through the text it reads the surrounding words. It also reads what I type. Nothing like this happens in your editor. BTW. Did you see <a href="http://www.w3.org/TR/2dcontext/#best-practices">http://www.w3.org/TR/2dcontext/#best-practices</a>?</blockquote><p>No, you didn’t. And you should have.</p><h3>Back to Square One (and a Half)</h3><p>I think the lesson learned is that contentEditable may be terrible, but it is already here. I’m sure that for all the issues that I mentioned there will be native APIs one day, but believe me — that day is not yet to come. Standardising such complex features is an extremely tough job, because what you see is still the tip of the iceberg. Even though I’m working with contentEditable for nearly four years (that’s nothing comparing to Frederico Knabben’s 13 :D) I still find W3C’s <a href="https://lists.w3.org/Archives/Public/public-webapps/">public-web-apps</a> and <a href="https://lists.w3.org/Archives/Public/public-editing-tf/">public-editing-tf</a> mailing lists eye-opening. Moreover, there are many use cases for editing in the browsers and even WYSIWYG text editors differ among themselves so it would be unfair to lock browsers just for one use case.</p><h3>The Editing Task Force</h3><p>Talking about standards — contentEditable needs one, because we need contentEditable. Years will pass before there will be any chance of implementing a full featured, stable and usable WYSIWYG editor without contentEditable. Therefore, the <a href="http://www.w3.org/wiki/Editing_Taskforce">W3C Editing Task Force</a> was created last year (which I and Frederico Knabben joined) where some tough discussions started on what to do with the current situation. I will write a separate post about this effort as it looks really promising.</p><p>(Edit: You can read more about contentEditable standardization in <a href="https://medium.com/content-uneditable/fixing-contenteditable-1a9a5073c35d">”Fixing ContentEditable”</a>.)</p><h3>ContentEditable — the Good Parts</h3><p>ContentEditable is like JavaScript, only Douglas Crockford hasn’t written a book about it yet. But (like JavaScript) it also has its good parts (yeah, I know — the good/bad ratio is debatable). It’s amazing that adding one attribute to an HTML element enables typing, selection, keyboard navigation, spell checking, drag and drop, pasting, undo manager. That all of this is integrated with the OS, that such editor can be used with a screen reader or on a touchscreen device and that it’s well <a href="https://en.wikipedia.org/wiki/Internationalization_and_localization">internationalised</a>. Let’s focus on these good parts and forget the bad ones.</p><p>Over the past years, while working on CKEditor I noticed that we were gradually replacing native features with our own implementations. It started with a custom behavior of the <em>Enter</em> key, commands (from the <em>execCommand()</em> API, to ability to apply, remove and check state of a specific style like <em>bold</em>), undo manager and intercepted pasting so the pasted content can be filtered out. Then some improvements to the selection system were added (such as locking it when the editor is blurred, which allows the implementation of modals) together with enhanced navigation in tables and completely custom list editing. Since version 4.0, CKEditor has its custom “insert HTML into selection” mechanism and a <a href="http://sdk.ckeditor.com/samples/magicline.html">feature allowing reaching non-editable places</a>. CKEditor 4.1 introduced highly customisable <a href="http://docs.ckeditor.com/#!/guide/dev_acf">content filtering</a> (no more mess on paste). CKEditor 4.3 brought support for <a href="http://sdk.ckeditor.com/samples/simplebox.html">non-editable islands with editable islands inside</a> which required overriding many native systems (selection, keyboard, focus, clipboard). Somewhere in the meantime we implemented custom <em>Backspace</em> and <em>Delete</em> support to workaround <a href="http://code.google.com/p/chromium/issues/detail?id=226941">Blink’s</a> and <a href="https://bugs.webkit.org/show_bug.cgi?id=114791">WebKit’s</a> broken implementations. Finally, just a few weeks ago we made a final takeover of the clipboard, which means that in some browsers copy, cut and paste operations are fully handled by CKEditor.</p><p>It means that today CKEditor does not let the browser do anything to the content except handling typing, some deleting and that’s basically it. At the same time, it still uses the native selection system, keyboard navigation and other APIs such as those related to clipboard or focus management.</p><p>With <a href="https://ckeditor.com/ckeditor-5/">CKEditor 5</a> we are planning to conclude this process by letting the browser insert text only, but with CKEditor’s control (edit: read more in <a href="https://medium.com/content-uneditable/ckeditor-5-the-future-of-rich-text-editing-2b9300f9df2c">“CKEditor 5: The Future of Rich Text Editing”</a>). Ironically, we plan to base all the editing algorithms on a custom data model as we agree that DOM is not the perfect tool for this job. Of course, we are reaching the moment where we may face internationalisation issues (like the support for <em>Alt+Backspace</em>) but we are aware of this. What’s more, this is the piece of functionality which may be opened by the browsers as one of the first ones, thanks to the work done by the Editing Task Force. I hope to write more about this in the near future (edit: read more in <a href="https://medium.com/content-uneditable/fixing-contenteditable-1a9a5073c35d">”Fixing ContentEditable”</a>).</p><h3><strong>Editing Framework</strong></h3><p>All this sounds nice, but the amount of work needed to reach such state is still huge. Even with the know-how it does not seem to be a project which can be approached by a single developer or even a medium-sized company. Therefore, we believe that an editing framework, which will allow other developers to build their customised solutions on top of it, needs to be implemented. This is one of the goals that we defined for CKEditor 5, however projects like <a href="http://alloyeditor.com/">Alloy Editor</a> prove that this is doable even with CKEditor 4. Only if it wasn’t for developers starting with a clean contentEditable as soon as they find one of the existing editors slightly disappointing, we could have been in a different place today ;).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=261a38555e9c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/content-uneditable/contenteditable-the-good-the-bad-and-the-ugly-261a38555e9c">ContentEditable — The Good, the Bad and the Ugly</a> was originally published in <a href="https://medium.com/content-uneditable">Content Uneditable</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>