How to implement a live spell checking?

SyntaxEditor for Windows Forms Forum

Posted 9 years ago by Joachim Schwieren
Version: 4.0.0283
Avatar
Hi,

SyntaxEditor has a feature to mark text with a red wavey line which is perfect for showing spelling errors in a text document.

My question is how can such a feature be implemented best? I'd like to know where the best place is to implement the actual checking and the updating of the highlighting.

Assume you have a method like this

public bool IsCorrectlySpelled(string word);

It tells you if a word is spelled correctly (no highlighting) or not (apply the wavey lines).

Also if you think of a dynamic syntax langauge that does e.g. HTML tag highlighting, I only want to perform the spell checking on the plain text, not on the HTML tags, attributes and so on.

Any ideas how to get this working ("best practise") would be nice?

Thanks for your help,

Joachim

Comments (3)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joachim,

Not sure if you were aware but we include a full source SpellCheckForm in the sample project that shows how you can make a spell checking dialog. You just need to look at the NOTE items in there and replace code as needed.

If you are looking to do some other sort of live spell checking without a dialog, then you'd want to render the results using wave line span indicators. The Indicators QuickStart shows you how you can add/remove those.

You'd probably want to kick off some process to scan words after text changes and then update the misspelled word indicators as appropriate. The spell check form we include shows how you can scan text and skip over comments, etc.


Actipro Software Support

Posted 9 years ago by Joachim Schwieren
Avatar
Hi,

thanks for your answer. Actually I know the sample with the dialog. But as you already stated, I want to do a "live" spell checking. I also know how to use the span indicators but my actual question is where should I do the spell checking?

Is the semantic parser the right place for that? I don't want to spellckeck the full document every time the text has changed. I only want to perform the spellchecking where it is required.

I thought you might have a "best practice" approach where to implement the checking routine...

Thanks!
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Joachim,

Right well the document's TextChanged method is a good place to do spell checking because it tells you what range has been modified. However the downside is that if that change range is huge, that event is still in the main thread, so your spell checking there could bog down your UI performance if it takes a while to do.

I believe the semantic parsing method is passed the range that was changed as well, so you could have your semantic parsing code do it in a different thread and return the results. If you had the semantic parser service enabled, that check would be multi-threaded. Then when the Document.SemanticParseData was updated, you'd have to update the appropriate ranges on the fly.

In the newer design we have with SyntaxEditor for WPF, live spell checking is much easier to do. We have more of a "pull" model there where we request adornments (things like wave lines) only for the displayed text. Meaning you never need to spell check the whole document, you just do it for lines that are rendered.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.