diff --git a/chrome/content/vimperator/bookmarks.js b/chrome/content/vimperator/bookmarks.js index d4ae7cf1..5875bd03 100644 --- a/chrome/content/vimperator/bookmarks.js +++ b/chrome/content/vimperator/bookmarks.js @@ -343,12 +343,64 @@ function History() //{{{ load(); history = history.filter(function(elem) { - return elem[0] != url; + return elem[0] != url; }); history.unshift([url, title]); 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); + } + } //}}} } //}}} diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js index 9e3258de..33216e7e 100644 --- a/chrome/content/vimperator/commands.js +++ b/chrome/content/vimperator/commands.js @@ -54,11 +54,11 @@ var g_hint_mappings = [ //{{{ ["", "vimperator.tabs.select('+1', true)", true, true], // same as gt, but no count supported ["", "vimperator.tabs.select('-1', true)", true, true], /* navigation */ - ["", "stepInHistory(g_count > 0 ? -1 * g_count : -1);", false, true], - ["", "stepInHistory(g_count > 0 ? g_count : 1);", false, true], - ["", "stepInHistory(g_count > 0 ? -1 * g_count : -1);", false, true], - ["", "stepInHistory(g_count > 0 ? g_count : 1);", false, true], - ["", "vimperator.tabs.remove(getBrowser().mCurrentTab, g_count, false, 0);", true, true], + ["", "vimperator.history.stepTo(g_count > 0 ? -1 * g_count : -1);", false, true], + ["", "vimperator.history.stepTo(g_count > 0 ? g_count : 1);", false, true], + ["", "vimperator.history.stepTo(g_count > 0 ? -1 * g_count : -1);", false, true], + ["", "vimperator.history.stepTo(g_count > 0 ? g_count : 1);", false, true], + ["", "vimperator.tabs.remove(getBrowser().mCurrentTab, g_count, false, 0);", true, true], /* cancel hint mode keys */ ["", "", true, true], ["", "", true, true], @@ -247,10 +247,10 @@ function Commands() //{{{ addDefaultCommand(new Command(["ba[ck]"], function(args, special, count) { - if(special) - historyGoToBeginning(); + if (special) + vimperator.history.goToStart(); else - stepInHistory(count > 0 ? -1 * count : -1); + vimperator.history.stepTo(count > 0 ? -1 * count : -1); }, { usage: ["{count}ba[ck][!]"], @@ -423,10 +423,10 @@ function Commands() //{{{ addDefaultCommand(new Command(["fo[rward]", "fw"], function(args, special, count) { - if(special) - historyGoToEnd(); + if (special) + vimperator.history.goToEnd(); else - stepInHistory(count > 0 ? count : 1); + vimperator.history.stepTo(count > 0 ? count : 1); }, { usage: ["{count}fo[rward][!]"], @@ -460,7 +460,7 @@ function Commands() //{{{ } )); addDefaultCommand(new Command(["hist[ory]", "hs"], - hsshow, + function() { vimperator.history.list(); }, { usage: ["hist[ory] {filter}"], short_help: "Show recently visited URLs", @@ -475,9 +475,12 @@ function Commands() //{{{ if (special) // open javascript console openURLsInNewTab("chrome://global/content/console.xul", true); else - try { + try + { eval(args); - } catch(e) { + } + catch (e) + { vimperator.echoerr(e.name + ": " + e.message); } }, @@ -532,7 +535,7 @@ function Commands() //{{{ addDefaultCommand(new Command(["o[pen]", "e[dit]"], function(args, special) { - if(args.length > 0) + if (args.length > 0) openURLs(args); else { @@ -1025,48 +1028,6 @@ function execute(string) 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 /////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////{{{ @@ -1106,14 +1067,14 @@ function openURLsInNewTab(str, activate) function stringToURLs(str) { 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 if (urls[url].match(/^(\.$|\.\/\S*)/)) { var newLocation = getCurrentLocation(); newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1"); - if(urls[url].match(/^\.(\/\S+)/)) + if (urls[url].match(/^\.(\/\S+)/)) newLocation += urls[url].replace(/^\.(\/\S+)/, "$1"); urls[url] = newLocation; @@ -1123,7 +1084,7 @@ function stringToURLs(str) { var newLocation = getCurrentLocation(); newLocation = newLocation.replace(/([\s\S]+\/)[^\/]*/, "$1/../"); - if(urls[url].match(/^\.\.(\/\S+)/)) + if (urls[url].match(/^\.\.(\/\S+)/)) newLocation += urls[url].replace(/^\.\.\/(\S+)/, "$1"); urls[url] = newLocation; @@ -1133,7 +1094,7 @@ function stringToURLs(str) { var newLocation = getCurrentLocation(); 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"); urls[url] = newLocation; @@ -1322,7 +1283,7 @@ function goUp(count) if (count < 1) count = 1; - for(var i=0; i