1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 21:57:58 +01:00

new gb and gB commands

This commit is contained in:
Martin Stubenschrott
2007-10-16 21:43:25 +00:00
parent 83df17f660
commit 233e5aa58a
4 changed files with 85 additions and 32 deletions

View File

@@ -31,6 +31,9 @@ function Buffer() //{{{
////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
// used for the "B" mapping to remember the last :buffer[!] command
var lastBufferSwitchArgs = "";
var lastBufferSwitchSpecial = true;
var zoom_levels = [ 1, 10, 25, 50, 75, 90, 100,
120, 150, 200, 300, 500, 1000, 2000 ];
@@ -124,6 +127,8 @@ function Buffer() //{{{
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
this.lastInputField = null; // used to keep track of the right field for "gi"
this.__defineGetter__("URL", function()
{
@@ -160,8 +165,6 @@ function Buffer() //{{{
return window.content.document.title;
});
this.lastInputField = null; // used to keep track of the right field for "gi"
// returns an XPathResult object
this.evaluateXPath = function(expression, doc, elem, ordered)
{
@@ -419,15 +422,75 @@ function Buffer() //{{{
vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex);
}
// XXX: should this be in v.buffers. or v.tabs.?
// "buffer" is a string which matches the URL or title of a buffer, if it
// is null, the last used string is used again
this.switchTo = function(buffer, allowNonUnique, count, reverse)
{
if (buffer != null)
{
// store this command, so it can be repeated with "B"
lastBufferSwitchArgs = buffer;
lastBufferSwitchSpecial = allowNonUnique;
}
else
{
buffer = lastBufferSwitchArgs;
if (typeof allowNonUnique == "undefined" || allowNonUnique == null)
allowNonUnique = lastBufferSwitchSpecial;
}
if (!count || count < 1)
count = 1;
if (typeof reverse != "boolean")
reverse = false;
var match;
if (match = buffer.match(/^(\d+):?/))
return vimperator.tabs.select(parseInt(match[1]) - 1, false); // make it zero-based
var matches = [];
var lower_buffer = buffer.toLowerCase();
var first = vimperator.tabs.index() + (reverse ? 0 : 1);
for (var i = 0; i < getBrowser().browsers.length; i++)
{
var index = (i + first) % getBrowser().browsers.length;
var url = getBrowser().getBrowserAtIndex(index).contentDocument.location.href;
var title = getBrowser().getBrowserAtIndex(index).contentDocument.title.toLowerCase();
if (url == buffer)
return vimperator.tabs.select(index, false);
if (url.indexOf(buffer) >= 0 || title.indexOf(lower_buffer) >= 0)
matches.push(index);
}
if (matches.length == 0)
vimperator.echoerr("E94: No matching buffer for " + buffer);
else if (matches.length > 1 && !allowNonUnique)
vimperator.echoerr("E93: More than one match for " + buffer);
else
{
if (reverse)
{
index = matches.length - count;
while (index < 0)
index += matches.length;
}
else
index = (count-1) % matches.length;
vimperator.tabs.select(matches[index], false);
}
};
this.zoomIn = function(steps, full_zoom)
{
bumpZoomLevel(steps, full_zoom);
}
};
this.zoomOut = function(steps, full_zoom)
{
bumpZoomLevel(-steps, full_zoom);
}
};
//}}}
} //}}}