views:

25

answers:

1

Actually i would like to modify the replaceWord function of the spellchecker.

I tried (in my own firefox extension) onInit:

original_replaceWord = InlineSpellCheckerUI.replaceWord;

InlineSpellCheckerUI.replaceWord = function()
{
    // things i would like to do (i.e. set the Cursor to another spot in the editor) 

    // call of the original function
    return original_replaceWord.apply(this, arguments);
};

But this didn't seem to work, because this function was not called when i replaced a missspelled word.

How do i find the right function? Which one do i need to overwrite?

thx for any suggestions

+1  A: 

Try this: (this is wrong. see the update below)

original_replaceWord = InlineSpellCheckerUI.replaceWord;

InlineSpellCheckerUI.prototype.replaceWord = function()
{
    // things i would like to do (i.e. set the Cursor to another spot in the editor) 

    // call of the original function
    return original_replaceWord.apply(this, arguments);
};

UPDATE

InlineSpellCheckerUI does not have the replaceWord function. The replaceWord function is defined in the nsIInlineSpellChecker interface which is realized by the mozInlineSpellChecker class in C++.

So you cannot override the replaceWord function. However, you can try overriding the replaceMisspelling function in InlineSpellCheckerUI using the code below. I think it should serve your purpose.

let original_replaceMisspelling = InlineSpellCheckerUI.replaceMisspelling;

InlineSpellCheckerUI.replaceMisspelling = function()
{
    // things i would like to do (i.e. set the Cursor to another spot in the editor) 

    // call of the original function
    return original_replaceMisspelling.apply(this, arguments);
};
abhin4v
Unfortunately, this did not work. I commented the original function out, but i still was able to replace misspelled words. Could it be that the spellchecking mechanism uses another function?
Thariama
as i thought i was overwriting the wrong function - this did the trick. Thank you very much!
Thariama