Thariama
Thariama

Reputation: 50832

Firefox-Addon: How do i overwrite a UI function?

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

Upvotes: 0

Views: 163

Answers (1)

Abhinav Sarkar
Abhinav Sarkar

Reputation: 23792

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);
};

Upvotes: 1

Related Questions