Firefox-Addon:如何覆盖UI功能?

时间:2010-09-15 10:01:10

标签: firefox firefox-addon

其实我想修改拼写检查程序 replaceWord 功能。

我尝试过(在我自己的firefox扩展程序中) 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);
};

但这似乎不起作用,因为当我替换了一个误导的单词时,没有调用此函数。

我如何找到合适的功能?我需要覆盖哪一个?

thx任何建议

1 个答案:

答案 0 :(得分:1)

试试这个 :(这是错误的。请参阅下面的更新)

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

<强>更新

InlineSpellCheckerUI没有replaceWord功能。 replaceWord函数在nsIInlineSpellChecker接口中定义,该接口由C ++中的mozInlineSpellChecker类实现。

因此您无法覆盖replaceWord功能。但是,您可以尝试使用以下代码覆盖replaceMisspelling中的InlineSpellCheckerUI功能。我认为它应该符合你的目的。

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