Comment 27 for bug 55760

Revision history for this message
In , Rbs (rbs) wrote :

> rbs, could you elaborate more on option (1)

You mentioned in comment 20 that "nsEditorSpellCheck::InitSpellChecker gets the
document associated with the editor instance and then walks the tree looking for
text nodes to spell check. For a xul:textbox, the document is
messengercompose.xul, so we start walking through our XUL file, spell checking
all of our xul text nodes!"

Assuming you managed to get hold of the editor inside the textbox as you said.
What I am suggesting is:

1. create a range to delimit the textbox
   nsCOMPtr<nsIDOMRange> spellCheckRange(do_CreateInstance(kRangeCID));
   spellCheckRange->SelectNodeContents(textBoxNode);

2. get the selection controller from the editor and hide the display
   nsCOMPtr<nsISelectionController> selCon;
   aEditor->GetSelectionController(getter_AddRefs(selCon));
   selCon->SetDisplaySelection(nsISelectionController::SELECTION_HIDDEN);

3. select the the textbox (selection is there, but won't show up due to 2.)
   nsCOMPtr<nsISelection> sel;
   selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
     getter_AddRefs(sel));
   sel->RemoveAllRanges();
   sel->AddRange(spellCheckRange);

4. Init the spell checker as you die=d, but with aEnableSelectionChecking=TRUE
   (see the code for the effect)
   InitSpellChecker(aEditor, PR_TRUE/*aEnableSelectionChecking*/)

5. restore the display so that the user sees the selections of the spell checker
   sel->RemoveAllRanges();
   selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);

6. Do the spell checking as you normally do...
----
This will only lookup what is in |spellCheckRange|. So _in general_, depending
on what you put spellCheckRange, you can restrict to whatever you want without
much re-design.