1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-06 06:34:13 +01:00

new alwayshints mode on ;a and F for quickhints in new tab

This commit is contained in:
Martin Stubenschrott
2007-10-25 23:30:10 +00:00
parent faefb78c24
commit 11815eaa73
5 changed files with 125 additions and 76 deletions

View File

@@ -52,11 +52,15 @@ vimperator.Events = function() //{{{
vimperator.buffer.updateBufferList();
}, false);
tabcontainer.addEventListener("TabSelect", function(event) {
if (vimperator.mode == vimperator.modes.HINTS)
vimperator.modes.reset();
vimperator.commandline.clear();
vimperator.modes.show();
vimperator.statusline.updateTabCount();
vimperator.buffer.updateBufferList();
vimperator.tabs.updateSelectionHistory();
setTimeout(function() { vimperator.focusContent(true); }, 10); // just make sure, that no widget has focus
}, false);
@@ -620,7 +624,8 @@ vimperator.Events = function() //{{{
vimperator.hints.onEvent(event);
event.preventDefault();
event.stopPropagation();
return false;
return true;
}
}

View File

@@ -35,10 +35,10 @@ vimperator.Hints = function() //{{{
var hints = [];
var valid_hints = []; // store the indices of the "hints" array with valid elements
var canUpdate = true;
var canUpdate = false;
var hintsGenerated = false;
var timeout = 200; // only update every 200ms when typing fast, not used yet
var wins = []; // keep track of the windows which we display the hints for
var docs = []; // keep track of the documents which we display the hints for
// this function 'click' an element, which also works
// for javascript links
@@ -148,7 +148,7 @@ vimperator.Hints = function() //{{{
win = window.content;
var doc = win.document;
wins.push(doc);
docs.push(doc);
var baseNodeAbsolute = doc.createElementNS("http://www.w3.org/1999/xhtml", "span");
baseNodeAbsolute.style.backgroundColor = "red";
@@ -201,9 +201,21 @@ vimperator.Hints = function() //{{{
hints.push([elem, text, span, elem.style.backgroundColor, elem.style.color]);
}
hintsGenerated = true;
return true;
}
// reset all important variables
function reset()
{
vimperator.statusline.updateInputBuffer("");
linkNumString = "";
hints = [];
valid_hints = [];
canUpdate = false;
hintsGenerated = false;
}
function showHints(win, str, start_idx)
{
if (!win)
@@ -275,6 +287,7 @@ outer:
function removeHints(doc, timeout)
{
vimperator.log(timeout);
if (!doc)
{
vimperator.log("Argument doc is required for internal removeHints() method", 9);
@@ -336,8 +349,11 @@ outer:
firstElem.style.color = firstElemColor;
}, timeout);
}
}
catch (e) { vimperator.log("Error hiding hints, probably wrong window"); }
reset();
};
function processHints(followFirst)
@@ -347,47 +363,57 @@ outer:
vimperator.beep();
return false;
}
else
if (!followFirst)
{
if (!followFirst)
var first_href = valid_hints[0].getAttribute("href") || null;
if (first_href)
{
var first_href = valid_hints[0].getAttribute("href") || null;
if (first_href)
{
if (valid_hints.some( function(e) { return e.getAttribute("href") != first_href; } ))
return false;
}
else if (valid_hints.length > 1)
if (valid_hints.some( function(e) { return e.getAttribute("href") != first_href; } ))
return false;
}
if (vimperator.modes.extended & vimperator.modes.QUICK_HINT)
openHint(false, false);
else
{
var loc = valid_hints.length > 0 ? valid_hints[0].href : "";
switch (submode)
{
case "f": focusHint(); break;
case "o": openHint(false, false); break;
case "O": vimperator.commandline.open(":", "open " + loc, vimperator.modes.EX); break;
case "t": openHint(true, false); break;
case "T": openHint(true, false); break;
case "T": vimperator.commandline.open(":", "tabopen " + loc, vimperator.modes.EX); break;
case "w": openHint(false, true); break;
case "W": vimperator.commandline.open(":", "winopen " + loc, vimperator.modes.EX); break;
case "a": saveHint(false); break;
case "s": saveHint(true); break;
case "y": yankHint(false); break;
case "Y": yankHint(true); break;
default:
vimperator.echoerr("INTERNAL ERROR: unknown submode: " + submode);
}
}
// I KNOW, ugly but this. is not available in this context :(
vimperator.hints.hide(null, !followFirst);
else if (valid_hints.length > 1)
return false;
}
var loc = valid_hints.length > 0 ? valid_hints[0].href : "";
switch (submode)
{
case "f": focusHint(); break;
case "o": openHint(false, false); break;
case "O": vimperator.commandline.open(":", "open " + loc, vimperator.modes.EX); break;
case "t": openHint(true, false); break;
case "T": openHint(true, false); break;
case "T": vimperator.commandline.open(":", "tabopen " + loc, vimperator.modes.EX); break;
case "w": openHint(false, true); break;
case "W": vimperator.commandline.open(":", "winopen " + loc, vimperator.modes.EX); break;
case "a": saveHint(false); break;
case "s": saveHint(true); break;
case "y": yankHint(false); break;
case "Y": yankHint(true); break;
default:
vimperator.echoerr("INTERNAL ERROR: unknown submode: " + submode);
}
var timeout = followFirst ? 0 : 500;
removeHints(docs.pop(), timeout);
if (vimperator.modes.extended & vimperator.modes.ALWAYS_HINT)
{
setTimeout(function() {
canUpdate = true;
linkNumString = "";
vimperator.statusline.updateInputBuffer("");
}, timeout);
}
else
{
setTimeout( function() {
if (vimperator.mode == vimperator.modes.HINTS)
vimperator.modes.reset(false);
}, timeout);
}
return true;
};
@@ -405,7 +431,7 @@ outer:
}
vimperator.modes.set(vimperator.modes.HINTS, mode);
submode = minor;
submode = minor || "o"; // open is the default mode
linkNumString = filter || "";
canUpdate = false;
@@ -432,26 +458,14 @@ outer:
return true;
};
this.hide = function(win, delayModeChange)
this.hide = function()
{
var timeout = delayModeChange ? 500 : 0;
doc = wins.pop();
if (!hintsGenerated)
return;
doc = docs.pop();
if(doc);
removeHints(doc, timeout);
vimperator.echo(" ");
vimperator.statusline.updateInputBuffer("");
linkNumString = "";
hints = [];
valid_hints = [];
canUpdate = false;
// only close this mode half a second later, so we don't trigger accidental actions so easily
setTimeout( function() {
if (vimperator.mode == vimperator.modes.HINTS)
vimperator.modes.reset(true);
}, timeout);
removeHints(doc, 0);
};
this.onEvent = function(event)
@@ -484,15 +498,34 @@ outer:
break;
default:
// pass any special or ctrl- etc. prefixed key back to the main vimperator loop
if (/^<./.test(key) || key == ":")
{
var map = null;
if ((map = vimperator.mappings.get(vimperator.modes.NORMAL, key)) ||
(map = vimperator.mappings.get(vimperator.modes.HINTS, key)))
{
map.execute(null, -1);
return;
}
vimperator.beep();
return;
}
linkNumString += key;
}
vimperator.statusline.updateInputBuffer(linkNumString);
if (canUpdate)
{
if (!hintsGenerated && linkNumString.length > 0)
generate();
showHints(null, linkNumString);
processHints(followFirst);
}
return false;
}

View File

@@ -1027,25 +1027,40 @@ vimperator.Mappings = function() //{{{
usage: ["f{hint}"],
help: "In QuickHint mode, every hintable item (according to the <code class=\"option\">'hinttags'</code> XPath query) is assigned a unique number (FIXME: numbers shown, but not usable yet).<br/>" +
"You can now either type this number or type any part of the URL which you want to follow, and it is followed as soon as it can be uniquely identified. " +
//"If you write the hint in ALLCAPS, the hint is followed in a background tab.<br/>" +
"Often it is can be useful to combine these techniques to narrow down results with some letters, and then typing a single digit to make the match unique.<br/>" +
"<code class=\"mapping\">&lt;Esc&gt;</code> stops this mode at any time."
}
));
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["F"],
function() { vimperator.echo("Always HINT mode not available anymore"); },
function() { vimperator.hints.show(vimperator.modes.QUICK_HINT, "t"); },
{
short_help: "Start AlwaysHint mode (CURRENTLY DISABLED)",
help: "In AlwaysHint mode, every hintable item (according to the <code class=\"option\">'hinttags'</code> XPath query) is assigned a label.<br/>" +
"If you then press the keys for a label, it is followed as soon as it can be uniquely identified. Labels stay active after following a hint in this mode, press <code class=\"mapping\">&lt;Esc&gt;</code> to stop this mode.<br/>" +
"This hint mode is especially useful for browsing large sites like Forums as hints are automatically regenerated when switching to a new document.<br/>" +
"Also, most <code class=\"mapping\">Ctrl</code>-prefixed shortcut keys are available in this mode for navigation."
short_help: "Start QuickHint mode, but open link in a new tab",
usage: ["F{hint}"],
help: "Like normal QuickMode (activated with <code class='mapping'>f</code>) but open the link in a new tab."
}
));
// addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["F"],
// function() { vimperator.echo("Always HINT mode not available anymore"); },
// {
// short_help: "Start AlwaysHint mode (CURRENTLY DISABLED)",
// help: "In AlwaysHint mode, every hintable item (according to the <code class=\"option\">'hinttags'</code> XPath query) is assigned a label.<br/>" +
// "If you then press the keys for a label, it is followed as soon as it can be uniquely identified. Labels stay active after following a hint in this mode, press <code class=\"mapping\">&lt;Esc&gt;</code> to stop this mode.<br/>" +
// "This hint mode is especially useful for browsing large sites like Forums as hints are automatically regenerated when switching to a new document.<br/>" +
// "Also, most <code class=\"mapping\">Ctrl</code>-prefixed shortcut keys are available in this mode for navigation."
// }
// ));
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], [";"],
function(arg) { vimperator.hints.show(vimperator.modes.EXTENDED_HINT, arg); },
function(arg)
{
short_help: "Start ExtendedHint mode",
if (arg == "a")
vimperator.hints.show(vimperator.modes.ALWAYS_HINT, "o");
else if (arg == "A")
vimperator.hints.show(vimperator.modes.ALWAYS_HINT, "t");
else
vimperator.hints.show(vimperator.modes.EXTENDED_HINT, arg);
},
{
short_help: "Start an extended Hint mode",
usage: [";{mode}{hint}"],
help: "ExtendedHint mode is useful, since in this mode you can yank link locations, open them in a new window or save images.<br/>" +
"If you want to yank the location of hint <code>24</code>, press <code class=\"mapping\">;y</code> to start this hint mode.<br/>" +