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

refactored some yanking code

This commit is contained in:
Martin Stubenschrott
2008-01-05 23:31:07 +00:00
parent 642ac2ba27
commit 43038f7566
5 changed files with 13 additions and 28 deletions

View File

@@ -392,20 +392,6 @@ vimperator.Buffer = function () //{{{
elem.dispatchEvent(evt); elem.dispatchEvent(evt);
}, },
yankElementText: function (elem)
{
var text = elem.textContent || "";
vimperator.copyToClipboard(text);
vimperator.echo("Yanked " + text, vimperator.commandline.FORCE_SINGLELINE);
},
yankElementLocation: function (elem)
{
var loc = elem.href || "";
vimperator.copyToClipboard(loc);
vimperator.echo("Yanked " + loc, vimperator.commandline.FORCE_SINGLELINE);
},
saveLink: function (elem, skipPrompt) saveLink: function (elem, skipPrompt)
{ {
var doc = elem.ownerDocument; var doc = elem.ownerDocument;

View File

@@ -334,6 +334,7 @@ vimperator.Hints = function () //{{{
return false; return false;
} }
var timeout = followFirst ? 0 : 500;
var activeIndex = (hintNumber ? hintNumber - 1 : 0); var activeIndex = (hintNumber ? hintNumber - 1 : 0);
var elem = validHints[activeIndex]; var elem = validHints[activeIndex];
var loc = elem.href || ""; var loc = elem.href || "";
@@ -352,14 +353,11 @@ vimperator.Hints = function () //{{{
case "V": vimperator.commands.viewsource(loc, true); break; case "V": vimperator.commands.viewsource(loc, true); break;
case "w": vimperator.buffer.followLink(elem, vimperator.NEW_WINDOW); break; case "w": vimperator.buffer.followLink(elem, vimperator.NEW_WINDOW); break;
case "W": vimperator.commandline.open(":", "winopen " + loc, vimperator.modes.EX); break; case "W": vimperator.commandline.open(":", "winopen " + loc, vimperator.modes.EX); break;
case "y": vimperator.buffer.yankElementLocation(elem); break; case "y": setTimeout(function(){vimperator.copyToClipboard(vimperator.buffer.URL, true)}, timeout + 50); break;
case "Y": vimperator.buffer.yankElementText(elem); break; case "Y": setTimeout(function(){vimperator.copyToClipboard(elem.textContent || "", true)}, timeout + 50); break;
default: default:
vimperator.echoerr("INTERNAL ERROR: unknown submode: " + submode); vimperator.echoerr("INTERNAL ERROR: unknown submode: " + submode);
} }
dump("3\n");
var timeout = followFirst ? 0 : 500;
removeHints(timeout); removeHints(timeout);
if (vimperator.modes.extended & vimperator.modes.ALWAYS_HINT) if (vimperator.modes.extended & vimperator.modes.ALWAYS_HINT)

View File

@@ -838,12 +838,7 @@ vimperator.Mappings = function () //{{{
} }
)); ));
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["y"], addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["y"],
function () function () { vimperator.copyToClipboard(vimperator.buffer.URL, true); },
{
var url = vimperator.buffer.URL;
vimperator.copyToClipboard(url);
vimperator.echo("Yanked " + url, vimperator.commandline.FORCE_SINGLELINE);
},
{ {
shortHelp: "Yank current location to the clipboard", shortHelp: "Yank current location to the clipboard",
help: "When running in X11 the location is also put into the selection, which can be pasted with the middle mouse button." help: "When running in X11 the location is also put into the selection, which can be pasted with the middle mouse button."
@@ -853,7 +848,10 @@ vimperator.Mappings = function () //{{{
function () function ()
{ {
var sel = window.content.document.getSelection(); var sel = window.content.document.getSelection();
vimperator.copyToClipboard(sel); if (sel)
vimperator.copyToClipboard(sel, true);
else
vimperator.beep();
}, },
{ {
shortHelp: "Copy selected text", shortHelp: "Copy selected text",

View File

@@ -95,7 +95,7 @@ vimperator.modes = (function () //{{{
{ {
// TODO: fix v.log() to work with verbosity level // TODO: fix v.log() to work with verbosity level
// vimperator.log("switching from mode " + oldMode + " to mode " + newMode, 7); // vimperator.log("switching from mode " + oldMode + " to mode " + newMode, 7);
dump("switching from mode " + oldMode + " to mode " + newMode + "\n"); // dump("switching from mode " + oldMode + " to mode " + newMode + "\n");
switch (oldMode) switch (oldMode)
{ {

View File

@@ -111,11 +111,14 @@ const vimperator = (function () //{{{
} }
}, },
copyToClipboard: function (str) copyToClipboard: function (str, verbose)
{ {
var clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"] var clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper); .getService(Components.interfaces.nsIClipboardHelper);
clipboardHelper.copyString(str); clipboardHelper.copyString(str);
if (verbose)
vimperator.echo("Yanked " + str, vimperator.commandline.FORCE_SINGLELINE);
}, },
execute: function (str, modifiers) execute: function (str, modifiers)