1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 19:37:59 +01:00

initial number support for hints, unpolished however

This commit is contained in:
Martin Stubenschrott
2007-10-31 16:31:15 +00:00
parent 346c8abb4b
commit 418181ad1e
4 changed files with 1452 additions and 2625 deletions

3945
ChangeLog

File diff suppressed because it is too large Load Diff

2
NEWS
View File

@@ -6,6 +6,8 @@
~/.vimperatorrc file instead for persistent options
* IMPORTANT! Major hints rewrite
read up the new help for the f, F and ; commands for details
removed the following hint options: 'hintchars'
added the following hint options: 'hinttimeout'
* you can edit textfields with Ctrl-i now using an external editor (thanks to Joseph Xu)
* :open, :bmarks, etc. filter on space separated tokens now, so you can
search with :open linux windows <tab> all your bookmarks/history

View File

@@ -28,8 +28,8 @@ the terms of any one of the MPL, the GPL or the LGPL.
vimperator.Hints = function() //{{{
{
var linkNumString = ""; // the typed link number is in this string
var linkNum = 1; // only the numerical part of the hint
var hintString = ""; // the typed string part of the hint is in this string
var hintNumber = 0; // only the numerical part of the hint
var submode = ""; // used for extended mode, can be "o", "t", "y", etc.
// hints[] = [elem, text, span, imgspan, elem.style.backgroundColor, elem.style.color]
@@ -38,7 +38,6 @@ vimperator.Hints = function() //{{{
var canUpdate = false;
var hintsGenerated = false;
var timeout = 200; // only update every 200ms when typing fast, not used yet
var docs = []; // keep track of the documents which we display the hints for
// this function 'click' an element, which also works
@@ -49,7 +48,7 @@ vimperator.Hints = function() //{{{
return false;
var x = 0, y = 0;
var elem = valid_hints[linkNum - 1];
var elem = valid_hints[hintNumber - 1] || valid_hints[0];
var elemTagName = elem.localName.toLowerCase();
elem.focus();
if (elemTagName == 'frame' || elemTagName == 'iframe')
@@ -81,7 +80,7 @@ vimperator.Hints = function() //{{{
if (valid_hints.length < 1)
return false;
var elem = valid_hints[linkNum - 1];
var elem = valid_hints[hintNumber - 1] || valid_hints[0];
var doc = window.content.document;
var elemTagName = elem.localName.toLowerCase();
if (elemTagName == 'frame' || elemTagName == 'iframe')
@@ -114,10 +113,11 @@ vimperator.Hints = function() //{{{
if (valid_hints.length < 1)
return false;
var elem = valid_hints[hintNumber - 1] || valid_hints[0];
if (text)
var loc = valid_hints[linkNum - 1].href;
var loc = elem.href;
else
var loc = valid_hints[linkNum - 1].textContent;
var loc = elem.textContent;
vimperator.copyToClipboard(loc);
vimperator.echo("Yanked " + loc, vimperator.commandline.FORCE_SINGLELINE);
@@ -128,7 +128,7 @@ vimperator.Hints = function() //{{{
if (valid_hints.length < 1)
return false;
var elem = valid_hints[linkNum - 1];
var elem = valid_hints[hintNumber - 1] || valid_hints[0];
var doc = elem.ownerDocument;
var url = makeURLAbsolute(elem.baseURI, elem.href);
var text = elem.textContent;
@@ -214,14 +214,24 @@ vimperator.Hints = function() //{{{
function reset()
{
vimperator.statusline.updateInputBuffer("");
linkNumString = "";
linkNum = 1;
hintString = "";
hintNumber = 0;
hints = [];
valid_hints = [];
canUpdate = false;
hintsGenerated = false;
}
// no safety checks are done, be careful with this function
// TODO: make it aware of imgspans
function showActiveHint(newID, oldID)
{
var oldElem = valid_hints[oldID - 1];
var newElem = valid_hints[newID - 1];
oldElem.style.backgroundColor = "yellow";
newElem.style.backgroundColor = "#88FF00";
}
function showHints(win, start_idx)
{
if (!win)
@@ -234,7 +244,7 @@ vimperator.Hints = function() //{{{
vimperator.echo("hint support for frameset pages not fully implemented yet");
}
vimperator.log("Show hints matching: " + linkNumString, 7);
vimperator.log("Show hints matching: " + hintString, 7);
var doc = win.document;
var scrollX = doc.defaultView.scrollX;
@@ -245,7 +255,7 @@ vimperator.Hints = function() //{{{
var height = window.content.innerHeight;
var width = window.content.innerWidth;
var find_tokens = linkNumString.split(/ +/);
var find_tokens = hintString.split(/ +/);
valid_hints = [];
outer:
@@ -302,7 +312,8 @@ outer:
{
if (!imgspan)
{
if (hintnum == linkNum)
var activeNum = hintNumber || 1;
if (hintnum == activeNum)
elem.style.backgroundColor = "#88FF00";
else
elem.style.backgroundColor = "yellow";
@@ -318,7 +329,7 @@ outer:
}
}
vimperator.log("Hinted " + valid_hints.length + " items of " + hints.length + " matching " + linkNumString, 7);
vimperator.log("Hinted " + valid_hints.length + " items of " + hints.length + " matching " + hintString, 7);
return true;
}
@@ -413,8 +424,16 @@ outer:
else if (valid_hints.length > 1)
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 loc = valid_hints.length > 0 ? valid_hints[linkNum - 1].href : "";
var activeNum = hintNumber || 1;
var loc = valid_hints[activeNum - 1].href || "";
switch (submode)
{
case ";": focusHint(); break;
@@ -439,8 +458,8 @@ outer:
{
setTimeout(function() {
canUpdate = true;
linkNumString = "";
linkNum = 1;
hintString = "";
hintNumber = 0;
vimperator.statusline.updateInputBuffer("");
}, timeout);
}
@@ -470,8 +489,8 @@ outer:
vimperator.modes.set(vimperator.modes.HINTS, mode);
submode = minor || "o"; // open is the default mode
linkNumString = filter || "";
linkNum = 1;
hintString = filter || "";
hintNumber = 0;
canUpdate = false;
generate();
@@ -518,39 +537,48 @@ outer:
break;
case "<Space>":
linkNumString += " ";
hintString += " ";
break;
case "<Tab>":
case "<S-Tab>":
var oldElem = valid_hints[linkNum - 1];
if (hintNumber == 0)
hintNumber = 1;
var oldID = hintNumber;
if (key == "<Tab>")
{
if (++linkNum > valid_hints.length)
linkNum = 1;
if (++hintNumber > valid_hints.length)
hintNumber = 1;
}
else
{
if (--linkNum < 1)
linkNum = valid_hints.length;
if (--hintNumber < 1)
hintNumber = valid_hints.length;
}
oldElem.style.backgroundColor = "yellow";
valid_hints[linkNum - 1].style.backgroundColor = "#88FF00";
showActiveHint(hintNumber, oldID);
return;
case "<BS>":
if (linkNumString == "")
if (hintNumber > 0)
{
hintNumber = Math.floor(hintNumber/10);
}
else if (hintString != "")
{
hintString = hintString.substr(0, hintString.length-1);
}
else
{
vimperator.beep();
return;
}
else
linkNumString = linkNumString.substr(0, linkNumString.length-1);
break;
case "<C-w>":
case "<C-u>":
linkNumString = "";
hintString = "";
hintNumber = 0;
break;
default:
@@ -569,13 +597,30 @@ outer:
return;
}
linkNumString += key;
if (/^[0-9]$/.test(key))
{
if (hintNumber == 0)
hintNumber = parseInt(key, 10);
else
hintNumber = (hintNumber * 10) + parseInt(key, 10);
vimperator.statusline.updateInputBuffer(hintString + (hintNumber > 0 ? hintNumber : ""));
if (hintNumber == 0 || hintNumber > valid_hints.length)
{
vimperator.beep();
return;
}
processHints(true);
return;
}
vimperator.statusline.updateInputBuffer(linkNumString);
hintString += key;
}
vimperator.statusline.updateInputBuffer(hintString + (hintNumber > 0 ? hintNumber : ""));
if (canUpdate)
{
if (!hintsGenerated && linkNumString.length > 0)
if (!hintsGenerated && hintString.length > 0)
generate();
showHints(null);

View File

@@ -429,12 +429,6 @@ vimperator.Options = function() //{{{
default_value: "homepage,quickmark,tabopen,paste"
}
));
this.add(new vimperator.Option(["autohints", "ah"], "boolean",
{
short_help: "Automatically show hints on every web page",
default_value: false
}
));
this.add(new vimperator.Option(["complete", "cpt"], "charlist",
{
short_help: "Items which are completed at the :[tab]open prompt",
@@ -505,10 +499,11 @@ vimperator.Options = function() //{{{
validator: function (value) { if (/[^mTb]/.test(value)) return false; else return true; }
}
));
this.add(new vimperator.Option(["hintchars", "hc"], "charlist",
this.add(new vimperator.Option(["hinttimeout", "hto"], "number",
{
short_help: "String of single characters which can be used to follow hints",
default_value: "hjklasdfgyuiopqwertnmzxcvb"
short_help: "Automatically follow non unique numerical hint after {arg} ms",
default_value: 500,
validator: function (value) { if (value >= 0) return true; else return false; }
}
));
this.add(new vimperator.Option(["hintstyle", "hs"], "string",