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

Somewhat better Y and :yank copy behavior that should work as expected on OS-X.

This commit is contained in:
Kris Maglione
2010-10-15 16:13:45 -04:00
parent c6c8b1e7ae
commit 4bbfa212bc
5 changed files with 40 additions and 35 deletions

View File

@@ -481,10 +481,7 @@ const Buffer = Module("buffer", {
controller.setCaretEnabled(caretmode); controller.setCaretEnabled(caretmode);
return String.match(selection, /\w*/)[0]; return String.match(selection, /\w*/)[0];
} }
if (util.computedStyle(range.startContainer).whiteSpace == "pre" return util.domToString(range);
&& util.computedStyle(range.endContainer).whiteSpace == "pre")
return String(range);
return String(selection);
}, },
/** /**

View File

@@ -583,9 +583,6 @@ const CommandLine = Module("commandline", {
this._lastMowOutput = <div class="ex-command-output" style={"white-space: " + style} highlight={highlightGroup}>{str}</div>; this._lastMowOutput = <div class="ex-command-output" style={"white-space: " + style} highlight={highlightGroup}>{str}</div>;
let output = util.xmlToDom(this._lastMowOutput, doc); let output = util.xmlToDom(this._lastMowOutput, doc);
if (!silent)
dactyl.triggerObserver("echoMultiline", str, highlightGroup, output);
// FIXME: need to make sure an open MOW is closed when commands // FIXME: need to make sure an open MOW is closed when commands
// that don't generate output are executed // that don't generate output are executed
if (this.widgets.mowContainer.collapsed) if (this.widgets.mowContainer.collapsed)
@@ -593,6 +590,9 @@ const CommandLine = Module("commandline", {
doc.body.appendChild(output); doc.body.appendChild(output);
if (!silent)
dactyl.triggerObserver("echoMultiline", str, highlightGroup, output);
commandline.updateOutputHeight(true); commandline.updateOutputHeight(true);
if (options["more"] && win.scrollMaxY > 0) { if (options["more"] && win.scrollMaxY > 0) {
@@ -1162,11 +1162,9 @@ const CommandLine = Module("commandline", {
dactyl.registerObserver("echoLine", observe, true); dactyl.registerObserver("echoLine", observe, true);
dactyl.registerObserver("echoMultiline", observe, true); dactyl.registerObserver("echoMultiline", observe, true);
function observe(str, highlight, dom) { function observe(str, highlight, dom) {
if (!observe.done) buffer.push(dom ? util.domToString(dom) : str)
buffer.push(dom ? util.domToString(dom) : str)
} }
dactyl.trapErrors.apply(dactyl, [fn, self].concat(Array.slice(arguments, 2))); dactyl.trapErrors.apply(dactyl, [fn, self].concat(Array.slice(arguments, 2)));
observe.done = true;
return buffer.join("\n"); return buffer.join("\n");
} }
}, { }, {

View File

@@ -32,7 +32,7 @@ Highlight.defaultValue("baseClass", function () /^(\w*)/.exec(this.class)[0]);
Highlight.defaultValue("selector", function () highlight.selector(this.class)); Highlight.defaultValue("selector", function () highlight.selector(this.class));
Highlight.defaultValue("sites", function () Highlight.defaultValue("sites", function ()
this.base ? this.base.sites this.base ? this.base.sites
: ["chrome://dactyl/*", "dactyl:*", "file://*", "resource://gre-resources/hiddenWindow.html"].concat( : ["chrome://dactyl/*", "dactyl:*", "file://*"].concat(
highlight.styleableChrome)); highlight.styleableChrome));
Highlight.defaultValue("style", function () Highlight.defaultValue("style", function ()
styles.addSheet(true, "highlight:" + this.class, this.sites, this.css, this.agent, true)); styles.addSheet(true, "highlight:" + this.class, this.sites, this.css, this.agent, true));

View File

@@ -56,15 +56,18 @@ const Services = Module("Services", {
this.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher); this.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher);
this.addClass("docshell", "@mozilla.org/docshell;1", [Ci.nsIBaseWindow, Ci.nsIWebNavigation, this.addClass("docshell", "@mozilla.org/docshell;1", [Ci.nsIBaseWindow, Ci.nsIWebNavigation,
Ci.nsIWebPageDescriptor, Ci.nsIWebProgress]); Ci.nsIWebPageDescriptor, Ci.nsIWebProgress]);
this.addClass("file", "@mozilla.org/file/local;1", Ci.nsILocalFile); this.addClass("file", "@mozilla.org/file/local;1", Ci.nsILocalFile);
this.addClass("file:", "@mozilla.org/network/protocol;1?name=file", Ci.nsIFileProtocolHandler); this.addClass("file:", "@mozilla.org/network/protocol;1?name=file", Ci.nsIFileProtocolHandler);
this.addClass("find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind); this.addClass("find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind);
this.addClass("process", "@mozilla.org/process/util;1", Ci.nsIProcess); this.addClass("htmlConverter","@mozilla.org/widget/htmlformatconverter;1", Ci.nsIFormatConverter);
this.addClass("timer", "@mozilla.org/timer;1", Ci.nsITimer); this.addClass("htmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", Ci.nsIDocumentEncoder);
this.addClass("xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", Ci.nsIXMLHttpRequest); this.addClass("process", "@mozilla.org/process/util;1", Ci.nsIProcess);
this.addClass("zipWriter", "@mozilla.org/zipwriter;1", Ci.nsIZipWriter); this.addClass("string", "@mozilla.org/supports-string;1", Ci.nsISupportsString);
this.addClass("timer", "@mozilla.org/timer;1", Ci.nsITimer);
this.addClass("xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", Ci.nsIXMLHttpRequest);
this.addClass("zipWriter", "@mozilla.org/zipwriter;1", Ci.nsIZipWriter);
}, },
_create: function (classes, ifaces, meth) { _create: function (classes, ifaces, meth) {

View File

@@ -43,10 +43,6 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
this.addObserver(this); this.addObserver(this);
this.overlays = {}; this.overlays = {};
let doc = services.get("appShell").hiddenDOMWindow.document;
this._div = this.xmlToDom(<div xmlns={XHTML}/>, doc);
doc.body.appendChild(this._div);
}, },
// FIXME: Only works for Pentadactyl // FIXME: Only works for Pentadactyl
@@ -267,18 +263,29 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
pattern.replace(/\\(.)/, function (m0, m1) chars.indexOf(m1) >= 0 ? m1 : m0), pattern.replace(/\\(.)/, function (m0, m1) chars.indexOf(m1) >= 0 ? m1 : m0),
domToString: function (node) { domToString: function (node) {
this._div.appendChild(this._div.ownerDocument.importNode(node, true)); if (node instanceof Ci.nsISelection && node.isCollapsed)
if (/^pre(-wrap)?$/.test(this.computedStyle(this._div.lastChild).whiteSpace)) return "";
var res = this._div.textContent;
else { if (node instanceof Ci.nsIDOMNode) {
let sel = this._div.ownerDocument.defaultView.getSelection(); let range = node.ownerDocument.createRange();
sel.removeAllRanges(); range.selectNode(node);
sel.selectAllChildren(this._div); node = range;
var res = sel.toString();
} }
while (this._div.firstChild) let doc = (node.getRangeAt ? node.getRangeAt(0) : node).startContainer.ownerDocument;
this._div.removeChild(this._div.firstChild);
return res; let encoder = services.create("htmlEncoder");
encoder.init(doc, "text/unicode", encoder.OutputRaw|encoder.OutputPreformatted);
if (node instanceof Ci.nsISelection)
encoder.setSelection(node);
else if (node instanceof Ci.nsIDOMRange)
encoder.setRange(node);
let str = services.create("string");
str.data = encoder.encodeToString();
let [result, length] = [{}, {}];
services.create("htmlConverter").convert("text/html", str, str.data.length*2, "text/unicode", result, length);
return result.value.QueryInterface(Ci.nsISupportsString).data;
}, },
/** /**