mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-07 00:34:12 +01:00
added :b# for switching to alternative buffer, also finally commited Kipling's patch to use getShortcutOrURI
This commit is contained in:
@@ -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
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 :)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user