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

added working hinttimeout option

This commit is contained in:
Martin Stubenschrott
2007-11-09 00:19:51 +00:00
parent 79c17fe9bd
commit 59d6412637
2 changed files with 25 additions and 8 deletions

View File

@@ -37,6 +37,7 @@ vimperator.Hints = function() //{{{
var hints = []; var hints = [];
var valid_hints = []; // store the indices of the "hints" array with valid elements var valid_hints = []; // store the indices of the "hints" array with valid elements
var activeTimeout = null; // needed for hinttimeout > 0
var canUpdate = false; var canUpdate = false;
var hintsGenerated = false; var hintsGenerated = false;
var docs = []; // keep track of the documents which we display the hints for var docs = []; // keep track of the documents which we display the hints for
@@ -421,13 +422,6 @@ outer:
else if (valid_hints.length > 1) else if (valid_hints.length > 1)
return false; return false;
} }
// if we write a numeric part like 3, but we have 45 hints, only follow
// the hint after a timeout, as the user might have wanted to follow link 34
else if (hintNumber > 0 && hintNumber * 10 <= valid_hints.length)
{
var timeout = vimperator.options["hinttimeout"];
return;
}
var activeNum = hintNumber || 1; var activeNum = hintNumber || 1;
var loc = valid_hints[activeNum - 1].href || ""; var loc = valid_hints[activeNum - 1].href || "";
@@ -528,6 +522,14 @@ outer:
{ {
var key = vimperator.events.toString(event); var key = vimperator.events.toString(event);
var followFirst = false; var followFirst = false;
// clear any timeout which might be active after pressing a number
if (activeTimeout)
{
clearTimeout(activeTimeout);
activeTimeout = null;
}
switch (key) switch (key)
{ {
case "<Return>": case "<Return>":
@@ -602,6 +604,7 @@ outer:
if (/^[0-9]$/.test(key)) if (/^[0-9]$/.test(key))
{ {
var oldHintNumber = hintNumber;
if (hintNumber == 0 || usedTabKey) if (hintNumber == 0 || usedTabKey)
{ {
usedTabKey = false; usedTabKey = false;
@@ -619,12 +622,25 @@ outer:
generate(); generate();
showHints(); showHints();
} }
showActiveHint(hintNumber, oldHintNumber || 1);
if (hintNumber == 0 || hintNumber > valid_hints.length) if (hintNumber == 0 || hintNumber > valid_hints.length)
{ {
vimperator.beep(); vimperator.beep();
return; return;
} }
// if we write a numeric part like 3, but we have 45 hints, only follow
// the hint after a timeout, as the user might have wanted to follow link 34
if (hintNumber > 0 && hintNumber * 10 <= valid_hints.length)
{
var timeout = vimperator.options["hinttimeout"];
if (timeout > 0)
activeTimeout = setTimeout(function() { processHints(true); }, timeout, true);
return false;
}
// we have a unique hint
processHints(true); processHints(true);
return; return;
} }

View File

@@ -516,7 +516,8 @@ vimperator.Options = function() //{{{
this.add(new vimperator.Option(["hinttimeout", "hto"], "number", this.add(new vimperator.Option(["hinttimeout", "hto"], "number",
{ {
short_help: "Automatically follow non unique numerical hint after {arg} ms", short_help: "Automatically follow non unique numerical hint after {arg} ms",
default_value: 500, help: "Set to 0 (the default) to only follow numeric hints after pressing &lt;Return&gt; or when the hint is unique.",
default_value: 0,
validator: function(value) { return value >= 0; } validator: function(value) { return value >= 0; }
} }
)); ));