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

added :b# for switching to alternative buffer, also finally commited Kipling's patch to use getShortcutOrURI

This commit is contained in:
Martin Stubenschrott
2008-07-28 22:16:04 +00:00
parent 23692e57aa
commit 60f040e54e
7 changed files with 59 additions and 82 deletions

View File

@@ -12,6 +12,7 @@ Inactive/former developers:
* Viktor Kojouharov (Виктор Кожухаров)
Patches (in no special order):
* Dominik Meister (:b# support)
* Konstantin Stepanov (:%foo support, :tabduplicate)
* Lukas Mai
* Guido Van Hoecke

View File

@@ -2,6 +2,7 @@
<b>Note:</b> If you don't wish to appear on this list when making a donation, please tell me.
2008:
* John Lusth
* Thomas Svensen
* Ryan McBride
* Brian Clark

1
NEWS
View File

@@ -10,6 +10,7 @@
generous donation which made this behavior possible)
* IMPORTANT: ctrl-x/a never take possible negative URLs into account, it was just
too unpredictable
* add :b# to select the alternate buffer
* add :tabduplicate command
* new 'urlseparator' option for specifying the regexp used to split the arg to
:open, :tabopen and :winopen

View File

@@ -383,53 +383,22 @@ liberator.Bookmarks = function () //{{{
return keywords;
},
// if @param engineName is null, it uses the default search engine
// full search string including engine name as first word in @param text
// if @param useDefSearch is true, it uses the default search engine
// @returns the url for the search string
// if the search also requires a postData, [url, postData] is returned
getSearchURL: function (text, engineName)
getSearchURL: function (text, useDefsearch)
{
var url = null;
var postData = null;
if (!engineName)
engineName = liberator.options["defsearch"];
var aPostDataRef = {};
var searchString = (useDefsearch? liberator.options["defsearch"] + " " : "") + text;
// we need to make sure our custom alias have been set, even if the user
// did not :open <tab> once before
this.getSearchEngines();
url = getShortcutOrURI(searchString, aPostDataRef);
if (url == searchString)
url = null;
// first checks the search engines for a match
var engine = searchService.getEngineByAlias(engineName);
if (engine)
{
if (text)
{
var submission = engine.getSubmission(text, null);
url = submission.uri.spec;
postData = submission.postData;
}
else
url = engine.searchForm;
}
else // check for keyword urls
{
if (!keywords)
load();
for (var i in keywords)
{
if (keywords[i][0] == engineName)
{
if (text == null)
text = "";
url = keywords[i][2].replace(/%s/g, encodeURIComponent(text));
break;
}
}
}
// if we came here, the engineName is neither a search engine or URL
if (postData)
return [url, postData];
if (aPostDataRef && aPostDataRef.value)
return [url, aPostDataRef.value];
else
return url; // can be null
},

View File

@@ -238,26 +238,7 @@ liberator.Tabs = function () //{{{
liberator.mappings.add([liberator.modes.NORMAL], ["<C-^>", "<C-6>"],
"Select the alternate tab",
function ()
{
if (liberator.tabs.alternate == null || liberator.tabs.getTab() == liberator.tabs.alternate)
{
liberator.echoerr("E23: No alternate page");
return;
}
// NOTE: this currently relies on v.tabs.index() returning the
// currently selected tab index when passed null
var index = liberator.tabs.index(liberator.tabs.alternate);
// TODO: since a tab close is more like a bdelete for us we
// should probably reopen the closed tab when a 'deleted'
// alternate is selected
if (index == -1)
liberator.echoerr("E86: Buffer does not exist"); // TODO: This should read "Buffer N does not exist"
else
liberator.tabs.select(index);
});
function () { liberator.tabs.selectAlternateTab(); });
}
/////////////////////////////////////////////////////////////////////////////}}}
@@ -748,10 +729,9 @@ liberator.Tabs = function () //{{{
switchTo: function (buffer, allowNonUnique, count, reverse)
{
if (buffer == "")
{
return;
}
else if (buffer != null)
if (buffer != null)
{
// store this command, so it can be repeated with "B"
lastBufferSwitchArgs = buffer;
@@ -764,6 +744,12 @@ liberator.Tabs = function () //{{{
allowNonUnique = lastBufferSwitchSpecial;
}
if (buffer == "#")
{
liberator.tabs.selectAlternateTab();
return;
}
if (!count || count < 1)
count = 1;
if (typeof reverse != "boolean")
@@ -829,6 +815,29 @@ liberator.Tabs = function () //{{{
return newTab;
},
selectAlternateTab: function ()
{
if (liberator.tabs.alternate == null || liberator.tabs.getTab() == liberator.tabs.alternate)
{
liberator.echoerr("E23: No alternate page");
return;
}
// NOTE: this currently relies on v.tabs.index() returning the
// currently selected tab index when passed null
var index = liberator.tabs.index(liberator.tabs.alternate);
// TODO: since a tab close is more like a bdelete for us we
// should probably reopen the closed tab when a 'deleted'
// alternate is selected
if (index == -1)
liberator.echoerr("E86: Buffer does not exist"); // TODO: This should read "Buffer N does not exist"
else
liberator.tabs.select(index);
return;
},
// TODO: when restarting a session FF selects the first tab and then the
// tab that was selected when the session was created. As a result the
// alternate after a restart is often incorrectly tab 1 when there

View File

@@ -285,40 +285,27 @@ liberator.util = { //{{{
// strip each 'URL' - makes things simpler later on
urls[url] = urls[url].replace(/^\s+/, "").replace(/\s+$/, "");
// first check if it is an existing local file but NOT a search url/keyword
// NOTE: the test for being a file is done first, because it's faster than getSearchURL
var file = liberator.io.getFile(urls[url]);
if (file.exists() && file.isReadable() && !liberator.bookmarks.getSearchURL("", urls[url]))
{
urls[url] = file.path;
continue;
}
// if the string doesn't look like a valid URL (i.e. contains a space
// or does not contain any of: .:/) try opening it with a search engine
// or keyword bookmark
if (liberator.has("bookmarks") && (/\s/.test(urls[url]) || !/[.:\/]/.test(urls[url])))
if (/\s/.test(urls[url]) || !/[.:\/]/.test(urls[url]))
{
var matches = urls[url].match(/^(\S+)(?:\s+(.+))?$/);
var alias = matches[1];
var text = matches[2] || null;
// TODO: it would be clearer if the appropriate call to
// getSearchURL was made based on whether or not the first word was
// indeed an SE alias rather than seeing if getSearchURL can
// process the call usefully and trying again if it fails - much
// like the comments below ;-)
// check if the first word is a search engine
var searchURL = liberator.bookmarks.getSearchURL(text, alias);
// check for a search engine match in the string
var searchURL = liberator.bookmarks.getSearchURL(urls[url], false);
if (searchURL)
{
urls[url] = searchURL;
continue;
}
else // the first word was not a search engine, search for the whole string in the default engine
else // no search engine match, search for the whole string in the default engine
{
searchURL = liberator.bookmarks.getSearchURL(urls[url], null);
searchURL = liberator.bookmarks.getSearchURL(urls[url], true);
if (searchURL)
{
urls[url] = searchURL;
@@ -327,6 +314,13 @@ liberator.util = { //{{{
}
}
var file = liberator.io.getFile(urls[url]);
if (file.exists() && file.isReadable())
{
urls[url] = file.path;
continue;
}
// if we are here let Firefox handle the url and hope it does
// something useful with it :)
}

View File

@@ -682,6 +682,8 @@ If argument is neither a full URL nor an index but uniquely identifies a
buffer, it is selected. With [!] the next buffer matching the argument is
selected, even if it cannot be identified uniquely. Use [m]b[m] as a
shortcut to open this prompt.
If argument is #, the alternate buffer will be selected (see [m]<C-6>[m]).
________________________________________________________________________________