Towards a Better Undo

The first few iterations of Scatterand used the browser’s built-in editing behavior pretty much as-is.  There are definitely some advantages to that — it’s consistent with other web sites that provide editing capabilities, and it is (or at least should be) better tested than anything that I could write from scratch in JavaScript.  But as Scatterand evolved, the browser’s built-in behavior kept being not good enough.  There’s no consistent way to get back to paragraph text after editing a heading.  There’s no way to create a multi-level list.  WebKit lacks a way to add table rows.  And those are just the obvious examples.

And so every version of Scatterand past the initial experiments provides a system for inserting “core” scripts into every document that capture key presses and manipulate the document in lieu of the browser’s default behavior.

Of course, if you’re going to implement any editing behavior in JavaScript, one of the first things you need to do is roll your own undo system.  See, the browser has a built-in undo, but it only applies to the browser’s built-in editing commands.  As soon as scripts start modifying the document, the browser’s undo system breaks — and breaks badly.  It starts undoing some of your changes and not others and generally mangles your work.  Clearly, this was not going to work.

As a stopgap measure I stuck in a script that just (*gulp*) stored a complete deep copy of the <body> element after every change.  That worked, for a certain definition of “worked”.  It was incredibly memory-hungry and kept breaking the other scripts, but it allowed me to put off writing a real, delta-based undo system.

Or at least put it off for a while — as it turns out, there are some things that you just can’t do if you can’t count on the identity of your elements to stay the same over the life of the document.  I got tired of having to getElementById() over and over on the same elements because you never know when the user might have hit the undo button and broken the identity of every element in the document.  I got tired of never being able to set script properties on DOM nodes because the undo system “lost” them.  I got tired of event handlers being completely unreliable because the undo system would periodically lose all of them.

And so I’m happy to announce that as of r48,the old, buggy, memory-hungry undo system has been replaced with a generic delta-based.  It makes a single deep copy of the document when the document is opened, and when a change is made, it updates the reference tree to match the document tree, recording the insertions, deletions, text and attribute changes that it made to reconcile the two.

The nice thing about the new undo system is that it’s completely generic.  Other scripts that modify the document don’t have to worry about making their changes “undoable” because the undo system will catch the changes automatically.  DOM nodes retain their identity across undos (and even across deletions — if you delete a node and then undo the change, you get the same node back).

All of this not only takes a huge bite out of Scatterand’s memory consumption, and makes it easier to write scripts — it fixes an entire category of bugs (“X not working after undo”) in one swoop.

You can get the code of the undo system (which should be able to stand alone), or the entire Scatterand project.  You can also get an easy to install deb package for Ubuntu systems.

Posted in Uncategorized | Comments Off

Web Search for Ubuntu Unity

It’s a bit tangential to our core purpose here (which, by the way, is to create a drop-in, collaborative web word processor script, that also happens to the the best word processor on your desktop), but Ubuntu users will be pleased to know that I’ve taken a (small) bit of time off of working on Scatterand to created a web search place for the Unity shell in Ubuntu 11.04.

Screenshot

As you can see from the above screenshot, rather than trying to displace the web browser in giving you a list of pages to peruse, the web search place takes on a different role:  getting to to a relevant information *source* quickly.  Click a source icon and you’ll be taken to a relevant page on that site.

Itching to try it out?  There’s a PPA on launchpad, and the entire source code (in Python) is available under the GPL.

Posted in Uncategorized | Comments Off

The Problem with the World

(Perhaps more accurately, “Why Scatterand Exists”)

I like the idea of web application, but I rarely find one that I actually like.  Or at least I rarely find one that I like as well as the desktop equivalent.  Web applications have their advantages, of course — effortless synchronization, easy collaboration, availability on any computer with an internet connection.  But when I am on my own computer, and I’m not trying to synchronize with other people, web apps just feel cheap and underpowered.

The problem with the world is that I have to choose between being able to work with documents over the web, and having a decent, full-featured editing interface on my desktop.  The Scatterand project exists to fix that problem.  Scatterand aims to be a web word processor and document editor that is also the best word processor on your desktop.

What makes Scatterand better?  Here are two guiding principles:

  • The server belongs to you. The server-side scripts for Scatterand are open source, pure Python, and able to run in the background on your own machine, or on any web server that supports WSGI.  That means that you control the feature set, and you control your data.  (Of course, you can still use Scatterand to set up a hosted service if you want to…)
  • The client belongs to the document.  Most web applications try to cram their entire user interface into the browser’s content frame.  With Scatterand, the page you get from the server is your document (it just happens to be editable).  On the desktop, a dedicated, webkit-based browser provides a native interface to the JavaScript based editing tools.  In the browser, Scatterand uses context menus and dialogs to make the editing controls as un-obtrusive as possible.

Scatterand is not finished or feature-complete, but it’s already useable as a simple rich text editor in a test environment.  You can check out the source code from the repository, or download ready-to-test Debian packages from the Scatterand PPA on Launchpad.

Posted in Uncategorized | Comments Off