2010-09-15 4 views
0

En fait, je voudrais modifier la fonction replaceWord de la spellchecker.Firefox-Addon: Comment remplacer une fonction d'interface utilisateur?

J'ai essayé (dans mon propre extension 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); 
}; 

Mais cela ne semble pas fonctionner, parce que cette fonction n'a pas été appelée lorsque j'ai remplacé un mot missspelled.

Comment trouver la bonne fonction? Lequel dois-je écraser?

thx pour toute suggestion

+0

Voir la source de InlineSpellCheckerUI à http://mxr.mozilla.org/firefox/source/toolkit/content/inlineSpellCheckUI.js et essayer de trouver la fonction que vous devez remplacer. –

+0

hmm, va essayer – Thariama

Répondre

1

Essayez cette : (. Ce qui ne va pas voir la mise à jour ci-dessous)

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

MISE À JOUR

InlineSpellCheckerUI n'a pas replaceWord fonction. La fonction replaceWord est définie dans l'interface nsIInlineSpellChecker qui est réalisée par la classe mozInlineSpellChecker en C++.

Vous ne pouvez donc pas remplacer la fonction replaceWord. Cependant, vous pouvez essayer de remplacer la fonction replaceMisspelling dans InlineSpellCheckerUI en utilisant le code ci-dessous. Je pense que cela devrait servir votre objectif.

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

Malheureusement, cela n'a pas fonctionné. J'ai commenté la fonction originale, mais je pouvais toujours remplacer les mots mal orthographiés. Se pourrait-il que le mécanisme de correction d'orthographe utilise une autre fonction? – Thariama

+0

comme je pensais que je remplaçais la mauvaise fonction - cela a fait l'affaire. Merci beaucoup! – Thariama

Questions connexes