diff --git a/content/buffer.js b/content/buffer.js index e2fb7426..3c494bb1 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -1312,31 +1312,14 @@ function Buffer() //{{{ docUrl, docCharset, reference, "selection"); }, - // url is optional viewSource: function (url, useExternalEditor) { url = url || buffer.URL; if (useExternalEditor) - { - // TODO: make that a helper function - // TODO: save return value in v:shell_error - var editor = options["editor"]; - var args = commands.parseArgs(editor, [], "*", true); - if (args.length < 1) - { - liberator.echoerr("No editor specified"); - return; - } - - var prog = args.shift(); - args.push(url); - liberator.callFunctionInThread(null, io.run, prog, args, true); - } + editor.editFileExternally(url); else - { liberator.open("view-source:" + url); - } }, zoomIn: function (steps, fullZoom) diff --git a/content/editor.js b/content/editor.js index aee4c8e3..d911ee25 100644 --- a/content/editor.js +++ b/content/editor.js @@ -295,7 +295,7 @@ function Editor() //{{{ mappings.add([modes.INSERT, modes.TEXTAREA, modes.COMPOSE], [""], "Edit text field with an external editor", - function () { editor.editWithExternalEditor(); }); + function () { editor.editFieldExternally(); }); // FIXME: does not work correctly mappings.add([modes.INSERT], @@ -794,14 +794,32 @@ function Editor() //{{{ return -1; }, - // TODO: clean up with 2 functions for textboxes and currentEditor? - editWithExternalEditor: function () + editFileExternally: function (path) { + // TODO: save return value in v:shell_error + let args = commands.parseArgs(options["editor"], [], "*", true); + + if (args.length < 1) + { + liberator.echoerr("No editor specified"); + return; + } + + args.push(path); + liberator.callFunctionInThread(null, io.run, args.shift(), args, true); + }, + + // TODO: clean up with 2 functions for textboxes and currentEditor? + editFieldExternally: function () + { + if (!options["editor"]) + return false; + var textBox = null; if (!(config.isComposeWindow)) textBox = document.commandDispatcher.focusedElement; - var text = ""; + var text = ""; // XXX if (textBox) text = textBox.value; else if (typeof GetCurrentEditor == "function") // Thunderbird composer @@ -809,14 +827,6 @@ function Editor() //{{{ else return false; - var editor = options["editor"]; - var args = commands.parseArgs(editor, [], "*", true); - if (args.length < 1) - { - liberator.echoerr("No editor specified"); - return false; - } - try { var tmpfile = io.createTempFile(); @@ -836,9 +846,6 @@ function Editor() //{{{ return false; } - var prog = args.shift(); - args.push(tmpfile.path); - if (textBox) { textBox.setAttribute("readonly", "true"); @@ -847,8 +854,7 @@ function Editor() //{{{ textBox.style.backgroundColor = "#bbbbbb"; } - // TODO: save return value in v:shell_error - liberator.callFunctionInThread(null, io.run, prog, args, true); + this.editFileExternally(tmpfile.path); if (textBox) textBox.removeAttribute("readonly"); diff --git a/content/muttator.js b/content/muttator.js index f37759bd..45aa4c7c 100644 --- a/content/muttator.js +++ b/content/muttator.js @@ -131,7 +131,7 @@ const config = { //{{{ // TODO: move mappings elsewhere, probably compose.js mappings.add([modes.COMPOSE], ["e"], "Edit message", - function () { editor.editWithExternalEditor(); }); + function () { editor.editFieldExternally(); }); mappings.add([modes.COMPOSE], ["y"], "Send message now", @@ -178,7 +178,7 @@ const config = { //{{{ if (options["autoexternal"] && !window.messageWasEditedExternally/* && !gMsgCompose.recycledWindow*/) { window.messageWasEditedExternally = true; - editor.editWithExternalEditor(); + editor.editFieldExternally(); } },