Emil’s Chronicle - The journal of Emil A Eklund

Taking a step back

Sometimes it’s necessary to taking a step back from what you are doing and consider what you are trying to do and if the chose path is the right one. In this case (yeah, I’m talking about my spell checker here) it clearly was not.

When I first started with it I made the choice to use a rich text component, even for the plain text implementation, and I also decided to to figure out what changes had been made based solely the caret position. As you’ve all probably seen it doesn’t really work well and the complexity of the code makes it hard to find and fix problems, especially without introducing new ones.

So I started to think about other ways to achieve the same thing and to use a textarea made a lot of sense. The problem with that of course is that textareas don’t allow markup. However the background of one can be set to transparent, and the text in can be duplicated and drawn directly behind it, and that text can have markup. The tricky part with that solution was to duplicate the text without having to recreate all of it after each change. After having tried a bunch of different ways of doing it I found one that seems to work pretty well, and that is to track the selection and caret both before and after the change, and then by comparing them determine the effected portion, and just update that.

Using this approach I’ve created an updated spell checker that’s not even nearly as buggy as the current one. Although it doesn’t support rich text I believe it’s a lot more useful.

Got a few more things I’d like to finish but I’ll post it in a little while, stay tuned.

One Response to 'Taking a step back'

  1. shiva Says:

    hope it will work tanx……..

Leave a Reply

(required)
(required, will not be published)