1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 16:07:59 +01:00

Update buffer.viewSource and buffer.viewSourceExternally prototypes. Update default 'editor' value to support columns in Vim.

This commit is contained in:
Kris Maglione
2011-06-27 18:52:41 -04:00
parent fb19a86c4b
commit d2c479f8a1
2 changed files with 30 additions and 12 deletions

View File

@@ -199,7 +199,11 @@ var Buffer = Module("buffer", {
dactyl.commands["buffer.viewSource"] = function (event) { dactyl.commands["buffer.viewSource"] = function (event) {
let elem = event.originalTarget; let elem = event.originalTarget;
buffer.viewSource([elem.getAttribute("href"), Number(elem.getAttribute("line"))]); let obj = { url: elem.getAttribute("href"), line: Number(elem.getAttribute("line")) };
if (elem.hasAttribute("column"))
obj.column = elem.getAttribute("column");
buffer.viewSource(obj);
}; };
}, },
@@ -917,26 +921,34 @@ var Buffer = Module("buffer", {
* specified *url*. Either the default viewer or the configured external * specified *url*. Either the default viewer or the configured external
* editor is used. * editor is used.
* *
* @param {string} url The URL of the source. * @param {string|object|null} loc If a string, the URL of the source,
* otherwise an object with some or all of the following properties:
*
* url: The URL to view.
* doc: The document to view.
* line: The line to select.
* column: the column to select.
*
* If no URL is provided, the current document is used.
* @default The current buffer. * @default The current buffer.
* @param {boolean} useExternalEditor View the source in the external editor. * @param {boolean} useExternalEditor View the source in the external editor.
*/ */
viewSource: function viewSource(url, useExternalEditor) { viewSource: function viewSource(loc, useExternalEditor) {
let doc = this.focusedFrame.document; let doc = this.focusedFrame.document;
if (isArray(url)) { if (isObject(loc)) {
if (options.get("editor").has("line")) if (options.get("editor").has("line") || !loc.url)
this.viewSourceExternally(url[0] || doc, url[1]); this.viewSourceExternally(loc.doc || loc.url || doc, loc);
else else
window.openDialog("chrome://global/content/viewSource.xul", window.openDialog("chrome://global/content/viewSource.xul",
"_blank", "all,dialog=no", "_blank", "all,dialog=no",
url[0], null, null, url[1]); loc.url, null, null, loc.line);
} }
else { else {
if (useExternalEditor) if (useExternalEditor)
this.viewSourceExternally(url || doc); this.viewSourceExternally(loc || doc);
else { else {
url = url || doc.location.href; let url = loc || doc.location.href;
const PREFIX = "view-source:"; const PREFIX = "view-source:";
if (url.indexOf(PREFIX) == 0) if (url.indexOf(PREFIX) == 0)
url = url.substr(PREFIX.length); url = url.substr(PREFIX.length);
@@ -959,13 +971,19 @@ var Buffer = Module("buffer", {
* immediately. * immediately.
* *
* @param {Document} doc The document to view. * @param {Document} doc The document to view.
* @param {function|object} callback If a function, the callback to be
* called with two arguments: the nsIFile of the file, and temp, a
* boolean which is true if the file is temporary. Otherwise, an object
* with line and column properties used to determine where to open the
* source.
* @optional
*/ */
viewSourceExternally: Class("viewSourceExternally", viewSourceExternally: Class("viewSourceExternally",
XPCOM([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), { XPCOM([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), {
init: function init(doc, callback) { init: function init(doc, callback) {
this.callback = callable(callback) ? callback : this.callback = callable(callback) ? callback :
function (file, temp) { function (file, temp) {
editor.editFileExternally({ file: file.path, line: callback }, editor.editFileExternally(update({ file: file.path }, callback || {}),
function () { temp && file.remove(false); }); function () { temp && file.remove(false); });
return true; return true;
}; };

View File

@@ -858,7 +858,7 @@ var Editor = Module("editor", {
options: function () { options: function () {
options.add(["editor"], options.add(["editor"],
"The external text editor", "The external text editor",
"string", "gvim -f +<line> <file>", { "string", "gvim -f '+<line><{|sil! call cursor(0, <column>)}>' <file>", {
format: function (obj, value) { format: function (obj, value) {
let args = commands.parseArgs(value || this.value, { argCount: "*", allowUnknownOptions: true }) let args = commands.parseArgs(value || this.value, { argCount: "*", allowUnknownOptions: true })
.map(util.compileMacro).filter(function (fmt) fmt.valid(obj)) .map(util.compileMacro).filter(function (fmt) fmt.valid(obj))