Implementing Spell Checking

SyntaxEditor for WPF Forum

Posted 9 years ago by Matt Gerrans
Version: 14.2.0611
Avatar

Hello,

I'm adding spell checking and I see there was a post asking about it about 5 years ago; in that reply it was suggested to use a SquiggleTagger to show the mispelled text, but beyond that, is there any recommended way of displaying/substituting in the words?    I guess an edit custom action, where you add the suggested words (along with "add to dictionary" and so on) to the menu, then when one is chosen, select use view.Selection.SelectWord() and view.ReplaceSelectedText() to change it would do the trick.   Another way would be to have the standard menu items (like "add to dictionary") along with an item to pop up a auto-complete session on the word, but that seems a bit more clunky.

Anyway, just checking before I start, as I'm sure you guys have done or seen more than one spell-checking implementation and may have some suggestions.

Comments (7)

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

Hi Matt,

We don't have anything additional at this time related to spell checking.  I would suggest using the squiggle tags to mark the spelling errors since that's a common way of doing it, and then customize the context menu to show spelling corrections when applicable.  One way to do this is to override SyntaxEditor.CreateDefaultContextMenu and customize the menu items from the base method call.


Actipro Software Support

Posted 9 years ago by Matt Gerrans
Avatar

Okay, thanks.    Just wanted to see if there were any best practices suggestions.

Yup, I'm already customizing the menu for some other things, so I'll add spelling suggestions there as well.

Posted 9 years ago by Matt Gerrans
Avatar

Hello again,

I have my spell checker working fine mostly except for one thing: when something external to the editor changes, I want my squiggle tagger to be refreshed.    That is, if I do a word replacement, everything works fine, but if I do something like "Ignore" or "Add to dictionary" the spell checker is now happy with the word, but it still has squiggles unless I do something like change the document in order to force a refresh of the squiggles.    Is there some way to programmatically "invalidate" the current squiggles?

[update]

PS: Unregistering the squiggle tagger and re-registering it gets the desired effect, but that doesn't seem like the most elegant approach.

[Modified 9 years ago]

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

Hi Matt,

The proper way is to raise the TagsChanged event on the tagger.  When you do that, the range you pass in the event arguments is told to refresh.


Actipro Software Support

Posted 9 years ago by Matt Gerrans
Avatar

Wow, getting my tagger is turning out to be a pain.    Is it some convoluted combination of GetService() + GetTagger() or something else?

The registration looks like this:

RegisterService(new CodeDocumentTaggerProvider<SpellingSquiggleTagger>(typeof(SpellingSquiggleTagger)));

 But this doesn't work:

Editor.Document.Language.GetService<SpellingSquiggleTagger>();

 So I guess first you do this:

var service = lang.GetService<CodeDocumentTaggerProvider<SpellingSquiggleTagger>>();
var tagger = service.GetTagger<SpellingSquiggleTagger>(Document); 

But that fails with an invalid cast.     I can't find any similar examples in the samples or anything useful in the docs...

I guess what I want is the tagger service that was produced by the CodeDocumentTaggerProvider, but where is that object?

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

Hi Matt,

The tagger itself is not a service, but the provider that creates it is.  That's why GetService won't work for getting the tagger.

When the tagger is installed, it will be available in the document's Properties collection like:

SpellingSquiggleTagger tagger = null;
if (document.Properties.TryGetValue(typeof(SpellingSquiggleTagger), out tagger)) {
    ...
}


Actipro Software Support

Posted 9 years ago by Matt Gerrans
Avatar

Ah ha.   Thanks!

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.