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

move the hsshow(), stepInHistory(), historyGoToBeginning(), and

historyGoToStart() global functions to vimperator.history
This commit is contained in:
Doug Kearns
2007-07-02 14:48:31 +00:00
parent 3ca1ee8651
commit 39878db0da
2 changed files with 83 additions and 80 deletions

View File

@@ -343,12 +343,64 @@ function History() //{{{
load(); load();
history = history.filter(function(elem) { history = history.filter(function(elem) {
return elem[0] != url; return elem[0] != url;
}); });
history.unshift([url, title]); history.unshift([url, title]);
return true; return true;
}; };
// TODO: better names?
this.stepTo = function(steps)
{
var index = getWebNavigation().sessionHistory.index + steps;
if (index >= 0 && index < getWebNavigation().sessionHistory.count)
{
getWebNavigation().gotoIndex(index);
}
else
{
vimperator.beep();
if (index < 0)
vimperator.echo("Cannot go past beginning of history");
else
vimperator.echo("Cannot go past end of history");
}
}
this.goToStart = function()
{
var index = getWebNavigation().sessionHistory.index;
if (index == 0)
{
vimperator.echo("Already at beginning of history");
return;
}
getWebNavigation().gotoIndex(0);
}
this.goToEnd = function()
{
var index = getWebNavigation().sessionHistory.index;
var max = getWebNavigation().sessionHistory.count -1;
if (index == max)
{
vimperator.echo("Already at end of history");
return;
}
getWebNavigation().gotoIndex(max);
}
this.list = function(filter, fullmode)
{
if (fullmode)
openURLsInNewTab("chrome://browser/content/history/history-panel.xul", true);
else
{
var items = vimperator.history.get(filter);
vimperator.previewwindow.show(items);
}
}
//}}} //}}}
} //}}} } //}}}

View File

@@ -54,11 +54,11 @@ var g_hint_mappings = [ //{{{
["<C-n>", "vimperator.tabs.select('+1', true)", true, true], // same as gt, but no count supported ["<C-n>", "vimperator.tabs.select('+1', true)", true, true], // same as gt, but no count supported
["<C-p>", "vimperator.tabs.select('-1', true)", true, true], ["<C-p>", "vimperator.tabs.select('-1', true)", true, true],
/* navigation */ /* navigation */
["<C-o>", "stepInHistory(g_count > 0 ? -1 * g_count : -1);", false, true], ["<C-o>", "vimperator.history.stepTo(g_count > 0 ? -1 * g_count : -1);", false, true],
["<C-i>", "stepInHistory(g_count > 0 ? g_count : 1);", false, true], ["<C-i>", "vimperator.history.stepTo(g_count > 0 ? g_count : 1);", false, true],
["<C-h>", "stepInHistory(g_count > 0 ? -1 * g_count : -1);", false, true], ["<C-h>", "vimperator.history.stepTo(g_count > 0 ? -1 * g_count : -1);", false, true],
["<C-l>", "stepInHistory(g_count > 0 ? g_count : 1);", false, true], ["<C-l>", "vimperator.history.stepTo(g_count > 0 ? g_count : 1);", false, true],
["<C-d>", "vimperator.tabs.remove(getBrowser().mCurrentTab, g_count, false, 0);", true, true], ["<C-d>", "vimperator.tabs.remove(getBrowser().mCurrentTab, g_count, false, 0);", true, true],
/* cancel hint mode keys */ /* cancel hint mode keys */
["<C-c>", "", true, true], ["<C-c>", "", true, true],
["<C-g>", "", true, true], ["<C-g>", "", true, true],
@@ -247,10 +247,10 @@ function Commands() //{{{
addDefaultCommand(new Command(["ba[ck]"], addDefaultCommand(new Command(["ba[ck]"],
function(args, special, count) function(args, special, count)
{ {
if(special) if (special)
historyGoToBeginning(); vimperator.history.goToStart();
else else
stepInHistory(count > 0 ? -1 * count : -1); vimperator.history.stepTo(count > 0 ? -1 * count : -1);
}, },
{ {
usage: ["{count}ba[ck][!]"], usage: ["{count}ba[ck][!]"],
@@ -423,10 +423,10 @@ function Commands() //{{{
addDefaultCommand(new Command(["fo[rward]", "fw"], addDefaultCommand(new Command(["fo[rward]", "fw"],
function(args, special, count) function(args, special, count)
{ {
if(special) if (special)
historyGoToEnd(); vimperator.history.goToEnd();
else else
stepInHistory(count > 0 ? count : 1); vimperator.history.stepTo(count > 0 ? count : 1);
}, },
{ {
usage: ["{count}fo[rward][!]"], usage: ["{count}fo[rward][!]"],
@@ -460,7 +460,7 @@ function Commands() //{{{
} }
)); ));
addDefaultCommand(new Command(["hist[ory]", "hs"], addDefaultCommand(new Command(["hist[ory]", "hs"],
hsshow, function() { vimperator.history.list(); },
{ {
usage: ["hist[ory] {filter}"], usage: ["hist[ory] {filter}"],
short_help: "Show recently visited URLs", short_help: "Show recently visited URLs",
@@ -475,9 +475,12 @@ function Commands() //{{{
if (special) // open javascript console if (special) // open javascript console
openURLsInNewTab("chrome://global/content/console.xul", true); openURLsInNewTab("chrome://global/content/console.xul", true);
else else
try { try
{
eval(args); eval(args);
} catch(e) { }
catch (e)
{
vimperator.echoerr(e.name + ": " + e.message); vimperator.echoerr(e.name + ": " + e.message);
} }
}, },
@@ -532,7 +535,7 @@ function Commands() //{{{
addDefaultCommand(new Command(["o[pen]", "e[dit]"], addDefaultCommand(new Command(["o[pen]", "e[dit]"],
function(args, special) function(args, special)
{ {
if(args.length > 0) if (args.length > 0)
openURLs(args); openURLs(args);
else else
{ {
@@ -1025,48 +1028,6 @@ function execute(string)
return execute_command.apply(this, tokens); return execute_command.apply(this, tokens);
} }
/////////////////////////////////////////////////////////////////////}}}
// navigation functions ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////{{{
function stepInHistory(steps)
{
var index = getWebNavigation().sessionHistory.index + steps;
if (index >= 0 && index < getWebNavigation().sessionHistory.count)
{
getWebNavigation().gotoIndex(index);
}
else
{
vimperator.beep();
if(index < 0)
vimperator.echo("Cannot go past beginning of history");
else
vimperator.echo("Cannot go past end of history");
}
}
function historyGoToBeginning()
{
var index = getWebNavigation().sessionHistory.index;
if (index == 0)
{
vimperator.echo("Already at beginning of history");
return;
}
getWebNavigation().gotoIndex(0);
}
function historyGoToEnd()
{
var index = getWebNavigation().sessionHistory.index;
var max = getWebNavigation().sessionHistory.count -1;
if (index == max)
{
vimperator.echo("Already at end of history");
return;
}
getWebNavigation().gotoIndex(max);
}
/////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////}}}
// url functions /////////////////////////////////////////////////////// // url functions ///////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////{{{
@@ -1106,14 +1067,14 @@ function openURLsInNewTab(str, activate)
function stringToURLs(str) function stringToURLs(str)
{ {
var urls = str.split(/\s*\|\s*/); var urls = str.split(/\s*\|\s*/);
begin: for(var url=0; url < urls.length; url++) begin: for (var url = 0; url < urls.length; url++)
{ {
// check for ./ and ../ (or even .../) to go to a file in the upper directory // check for ./ and ../ (or even .../) to go to a file in the upper directory
if (urls[url].match(/^(\.$|\.\/\S*)/)) if (urls[url].match(/^(\.$|\.\/\S*)/))
{ {
var newLocation = getCurrentLocation(); var newLocation = getCurrentLocation();
newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1"); newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1");
if(urls[url].match(/^\.(\/\S+)/)) if (urls[url].match(/^\.(\/\S+)/))
newLocation += urls[url].replace(/^\.(\/\S+)/, "$1"); newLocation += urls[url].replace(/^\.(\/\S+)/, "$1");
urls[url] = newLocation; urls[url] = newLocation;
@@ -1123,7 +1084,7 @@ function stringToURLs(str)
{ {
var newLocation = getCurrentLocation(); var newLocation = getCurrentLocation();
newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1/../"); newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1/../");
if(urls[url].match(/^\.\.(\/\S+)/)) if (urls[url].match(/^\.\.(\/\S+)/))
newLocation += urls[url].replace(/^\.\.\/(\S+)/, "$1"); newLocation += urls[url].replace(/^\.\.\/(\S+)/, "$1");
urls[url] = newLocation; urls[url] = newLocation;
@@ -1133,7 +1094,7 @@ function stringToURLs(str)
{ {
var newLocation = getCurrentLocation(); var newLocation = getCurrentLocation();
newLocation = newLocation.replace(/([\s\S]+):\/\/\/?(\S+?)\/\S*/, "$1://$2/"); newLocation = newLocation.replace(/([\s\S]+):\/\/\/?(\S+?)\/\S*/, "$1://$2/");
if(urls[url].match(/^\.\.\.(\/\S+)/)) if (urls[url].match(/^\.\.\.(\/\S+)/))
newLocation += urls[url].replace(/^\.\.\.\/(\S+)/, "$1"); newLocation += urls[url].replace(/^\.\.\.\/(\S+)/, "$1");
urls[url] = newLocation; urls[url] = newLocation;
@@ -1322,7 +1283,7 @@ function goUp(count)
if (count < 1) if (count < 1)
count = 1; count = 1;
for(var i=0; i<count-1; i--) for (var i = 0; i < count - 1; i--)
gocmd += "../"; gocmd += "../";
openURLs(gocmd); openURLs(gocmd);
@@ -1366,15 +1327,15 @@ function bmadd(str)
var res = Bookmarks.parseBookmarkString(str); var res = Bookmarks.parseBookmarkString(str);
if (res) if (res)
{ {
if(res.url == null) if (res.url == null)
{ {
res.url = getCurrentLocation(); res.url = getCurrentLocation();
// also guess title if the current url is :bmadded // also guess title if the current url is :bmadded
if(res.title == null) if (res.title == null)
res.title = getCurrentTitle(); res.title = getCurrentTitle();
} }
if(res.title == null) // title could still be null if (res.title == null) // title could still be null
res.title = res.url; res.title = res.url;
vimperator.bookmarks.add(res.title, res.url); vimperator.bookmarks.add(res.title, res.url);
@@ -1389,7 +1350,7 @@ function bmdel(str)
var res = Bookmarks.parseBookmarkString(str); var res = Bookmarks.parseBookmarkString(str);
if (res) if (res)
{ {
if(res.url == null) if (res.url == null)
res.url = getCurrentLocation(); res.url = getCurrentLocation();
var del = vimperator.bookmarks.remove(res.url); var del = vimperator.bookmarks.remove(res.url);
@@ -1409,16 +1370,6 @@ function bmshow(filter, fullmode)
vimperator.previewwindow.show(items); vimperator.previewwindow.show(items);
} }
} }
function hsshow(filter, fullmode)
{
if (fullmode)
openURLsInNewTab("chrome://browser/content/history/history-panel.xul", true);
else
{
var items = vimperator.history.get(filter);
vimperator.previewwindow.show(items);
}
}
/////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////}}}
// tab/buffer related functions //////////////////////////////////////// // tab/buffer related functions ////////////////////////////////////////
@@ -1703,9 +1654,9 @@ Vimperator.prototype.source = function(filename, silent)
[prev_match, heredoc, end] = multiliner(line, prev_match, heredoc); [prev_match, heredoc, end] = multiliner(line, prev_match, heredoc);
}); });
} }
catch(e) catch (e)
{ {
if(!silent) if (!silent)
vimperator.echoerr(e); vimperator.echoerr(e);
} }
} }
@@ -1713,7 +1664,7 @@ Vimperator.prototype.source = function(filename, silent)
// returns an XPathResult object // returns an XPathResult object
function evaluateXPath(expression, doc, ordered) function evaluateXPath(expression, doc, ordered)
{ {
if(!doc) if (!doc)
doc = window.content.document; doc = window.content.document;
var res = doc.evaluate(expression, doc, var res = doc.evaluate(expression, doc,