1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 17:27:57 +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 ~/.vimperatorrc file instead for persistent options
* IMPORTANT! Major hints rewrite * IMPORTANT! Major hints rewrite
read up the new help for the f, F and ; commands for details 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) * 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 * :open, :bmarks, etc. filter on space separated tokens now, so you can
search with :open linux windows <tab> all your bookmarks/history search with :open linux windows <tab> all your bookmarks/history

View File

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

View File

@@ -429,12 +429,6 @@ vimperator.Options = function() //{{{
default_value: "homepage,quickmark,tabopen,paste" 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", this.add(new vimperator.Option(["complete", "cpt"], "charlist",
{ {
short_help: "Items which are completed at the :[tab]open prompt", 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; } 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", short_help: "Automatically follow non unique numerical hint after {arg} ms",
default_value: "hjklasdfgyuiopqwertnmzxcvb" default_value: 500,
validator: function (value) { if (value >= 0) return true; else return false; }
} }
)); ));
this.add(new vimperator.Option(["hintstyle", "hs"], "string", this.add(new vimperator.Option(["hintstyle", "hs"], "string",