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
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);
};
精彩评论