我正在嘗試創建一個簡單的Thunderbird擴展,它在回覆郵件時對plain/text
消息進行操作。在對當前編輯器的內容進行修改後,我需要將光標放在特定的位置上,因爲現在光標始終放在回覆的末尾。如何在Thunderbird擴展中通過javascript在nsIEditor/nsIPlaintextEditor中設置光標位置?
這可能嗎?我幾乎到處搜索,但沒有找到解決辦法。 我在這裏花了幾個小時:
- https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/NsIEditor
- http://mdn.beonex.com/en/Extensions/Thunderbird/HowTos/Common_Thunderbird_Use_Cases/Compose_New_Message.html#Modify_Message_Body
- 和其他人(我至少需要10聲譽後超過2個鏈接)。
關於該插件的幾句話。該插件執行一項簡單工作,它在回覆時刪除引用消息中的所有「空白」行。我的JavaScript文件的簡化版本:
var myStateListener = {
init: function (e) {
gMsgCompose.RegisterStateListener(myStateListener);
},
NotifyComposeFieldsReady: function() {
// alter message fields here
},
NotifyComposeBodyReady: function() {
// alter message body here
try {
var editor = GetCurrentEditor();
var editor_type = GetCurrentEditorType();
editor.beginTransaction();
editor.beginningOfDocument();
// plain text editor
if (editor_type == "textmail" || editor_type == "text") {
var content = editor.outputToString('text/plain', 4);
var contentArray = content.split(/\r?\n/);
var contentArrayLength = contentArray.length;
var newContentArray = [];
for (var i = 0; i < contentArrayLength; i++) {
// match "non-empty" lines
if (!/^>{1,} *$/.test(contentArray[i])) {
// Add non-matching rows
newContentArray.push(contentArray[i]);
}
}
// join array of newContent lines
newContent = newContentArray.join("\r\n");
// select current content
editor.selectAll();
// replace selected editor content with cleaned-up content
editor.insertText(newContent);
} else {
// HTML messages not handled yet
void(null);
}
editor.endTransaction();
} catch (ex) {
Components.utils.reportError(ex);
return false;
}
},
ComposeProcessDone: function (aResult) {
//
},
SaveInFolderDone: function (folderURI) {
//
}
};
//
window.addEventListener("compose-window-init", myStateListener.init, true);
我是Thunderbird Plugins的新手,所以任何幫助將不勝感激。我應該閱讀哪些內容,在哪裏可以找到完整且有效的文檔,例子等。
在此先感謝。
程序員不接受有關實現代碼或查找文檔,示例或其他資源的問題。 – 2015-03-12 23:59:18
我已標記爲遷移到StackOverflow。 – 2015-03-13 00:00:25
好的,很抱歉,謝謝你移植我的問題。 – 2015-03-13 00:04:16