mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-10 15:44:12 +01:00
Somewhat better Y and :yank copy behavior that should work as expected on OS-X.
This commit is contained in:
@@ -32,7 +32,7 @@ Highlight.defaultValue("baseClass", function () /^(\w*)/.exec(this.class)[0]);
|
||||
Highlight.defaultValue("selector", function () highlight.selector(this.class));
|
||||
Highlight.defaultValue("sites", function ()
|
||||
this.base ? this.base.sites
|
||||
: ["chrome://dactyl/*", "dactyl:*", "file://*", "resource://gre-resources/hiddenWindow.html"].concat(
|
||||
: ["chrome://dactyl/*", "dactyl:*", "file://*"].concat(
|
||||
highlight.styleableChrome));
|
||||
Highlight.defaultValue("style", function ()
|
||||
styles.addSheet(true, "highlight:" + this.class, this.sites, this.css, this.agent, true));
|
||||
|
||||
@@ -56,15 +56,18 @@ const Services = Module("Services", {
|
||||
this.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher);
|
||||
|
||||
|
||||
this.addClass("docshell", "@mozilla.org/docshell;1", [Ci.nsIBaseWindow, Ci.nsIWebNavigation,
|
||||
Ci.nsIWebPageDescriptor, Ci.nsIWebProgress]);
|
||||
this.addClass("file", "@mozilla.org/file/local;1", Ci.nsILocalFile);
|
||||
this.addClass("file:", "@mozilla.org/network/protocol;1?name=file", Ci.nsIFileProtocolHandler);
|
||||
this.addClass("find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind);
|
||||
this.addClass("process", "@mozilla.org/process/util;1", Ci.nsIProcess);
|
||||
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);
|
||||
this.addClass("docshell", "@mozilla.org/docshell;1", [Ci.nsIBaseWindow, Ci.nsIWebNavigation,
|
||||
Ci.nsIWebPageDescriptor, Ci.nsIWebProgress]);
|
||||
this.addClass("file", "@mozilla.org/file/local;1", Ci.nsILocalFile);
|
||||
this.addClass("file:", "@mozilla.org/network/protocol;1?name=file", Ci.nsIFileProtocolHandler);
|
||||
this.addClass("find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind);
|
||||
this.addClass("htmlConverter","@mozilla.org/widget/htmlformatconverter;1", Ci.nsIFormatConverter);
|
||||
this.addClass("htmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", Ci.nsIDocumentEncoder);
|
||||
this.addClass("process", "@mozilla.org/process/util;1", Ci.nsIProcess);
|
||||
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) {
|
||||
|
||||
@@ -43,10 +43,6 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
|
||||
this.addObserver(this);
|
||||
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
|
||||
@@ -267,18 +263,29 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
pattern.replace(/\\(.)/, function (m0, m1) chars.indexOf(m1) >= 0 ? m1 : m0),
|
||||
|
||||
domToString: function (node) {
|
||||
this._div.appendChild(this._div.ownerDocument.importNode(node, true));
|
||||
if (/^pre(-wrap)?$/.test(this.computedStyle(this._div.lastChild).whiteSpace))
|
||||
var res = this._div.textContent;
|
||||
else {
|
||||
let sel = this._div.ownerDocument.defaultView.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.selectAllChildren(this._div);
|
||||
var res = sel.toString();
|
||||
if (node instanceof Ci.nsISelection && node.isCollapsed)
|
||||
return "";
|
||||
|
||||
if (node instanceof Ci.nsIDOMNode) {
|
||||
let range = node.ownerDocument.createRange();
|
||||
range.selectNode(node);
|
||||
node = range;
|
||||
}
|
||||
while (this._div.firstChild)
|
||||
this._div.removeChild(this._div.firstChild);
|
||||
return res;
|
||||
let doc = (node.getRangeAt ? node.getRangeAt(0) : node).startContainer.ownerDocument;
|
||||
|
||||
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;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user