【发布时间】:2015-03-12 23:51:21
【问题描述】:
我正在尝试创建一个简单的 Thunderbird 扩展,它在回复消息时对 plain/text 消息进行操作。在对当前编辑器的内容进行修改后,我需要将光标放在特定位置,因为现在光标总是放在回复的末尾。
这可能吗?我几乎到处搜索,但没有找到解决方案。 我在这里待了几个小时:
- 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 插件的新手,因此我们将不胜感激。我应该阅读什么,在哪里可以找到完整有效的文档、示例等。
提前致谢。
【问题讨论】:
-
程序员不接受有关实现代码或查找文档、示例或其他资源的问题。
-
我已标记为迁移到 StackOverflow。
-
好的,抱歉,感谢您迁移我的问题。
标签: javascript plugins xul thunderbird-addon