[Vimperator] Configurable hints for vimperator 0.6
Daniel Trstenjak
Daniel.Trstenjak at online.de
Sat Apr 26 13:44:57 PDT 2008
Hi all,
this is a patch for the current cvs version of vimperator 0.6.
It contains:
- hintstyle option again working
- new options linkfgcolor/linkbgcolor/activelinkfgcolor/activelinkbgcolor
- new option hintmatching
With the color options the look of the links during the hint mode can be
configured.
The hintmatching option introduces a new way of chooing links. The
option value 'contains' represents the vimperator 0.6 way, the typed
characters have to appear anywhere inside the link text. With the option
value 'startswith', the typed characters have to appear in the typed
order and at the beginning of the link text.
The default behaviour of vimperator 0.6 hasn't changed.
Greetings,
Daniel
-------------- next part --------------
? downloads
? vimperator-0.6pre.patch
? src/build.0.6pre.Linux
? src/chrome/vimperator.jar
? src/locale/en-US/autocommands.html
? src/locale/en-US/browsing.html
? src/locale/en-US/buffer.html
? src/locale/en-US/developer.html
? src/locale/en-US/intro.html
? src/locale/en-US/marks.html
? src/locale/en-US/options.html
? src/locale/en-US/repeat.html
? src/locale/en-US/starting.html
? src/locale/en-US/tabs.html
? src/locale/en-US/various.html
Index: src/vimperator.vim
===================================================================
RCS file: /cvs/vimperator/src/vimperator.vim,v
retrieving revision 1.30
diff -u -r1.30 vimperator.vim
--- src/vimperator.vim 7 Apr 2008 14:28:18 -0000 1.30
+++ src/vimperator.vim 26 Apr 2008 20:25:50 -0000
@@ -38,10 +38,11 @@
syn match vimperatorCommandWrapper "\%(^\s*:\=\)\@<=\%(!\|\h\w*\>\)" contains=vimperatorCommand
syn region vimperatorSet matchgroup=vimperatorCommand start="\%(^\s*:\=\)\@<=\<set\=\>" end="$" keepend oneline contains=vimperatorOption
-syn keyword vimperatorOption activate act complete cpt defsearch ds editor extendedhinttags eht focusedhintstyle fhs fullscreen fs
- \ nofullscreen nofs guioptions go hintstyle hs hinttags ht hinttimeout hto history hi hlsearch hls nohlsearch nohls
- \ hlsearchstyle hlss nohlsearchstyle nohlss incsearch is noincsearch nois ignorecase ic noignorecase noic insertmode im
- \ noinsertmode noim laststatus ls linksearch lks nolinksearch nolks more nextpattern nomore pageinfo pa popups pps preload
+syn keyword vimperatorOption activate act activelinkfgcolor alfc activelinkbgcolor albc complete cpt defsearch ds editor extendedhinttags eht
+ \ focusedhintstyle fhs fullscreen fs nofullscreen nofs guioptions go hintstyle hs hinttags ht hinttimeout hto history hi
+ \ hlsearch hls nohlsearch nohls hlsearchstyle hlss nohlsearchstyle nohlss incsearch is noincsearch nois ignorecase ic
+ \ noignorecase noic insertmode im noinsertmode noim laststatus ls linkbgcolor lbc linkfgcolor lfc linksearch lks linkmatching lm
+ \ nolinksearch nolks more nextpattern nomore pageinfo pa popups pps preload
\ nopreload previewheight pvh previouspattern scroll scr showmode smd noshowmode nosmd showstatuslinks ssli showtabline
\ stal smartcase scs nosmartcase noscs titlestring usermode um nousermode noum verbose vbs visualbell vb novisualbell novb
\ wildmode wim wildoptions wop
Index: src/content/hints.js
===================================================================
RCS file: /cvs/vimperator/src/content/hints.js,v
retrieving revision 1.55
diff -u -r1.55 hints.js
--- src/content/hints.js 30 Mar 2008 13:13:41 -0000 1.55
+++ src/content/hints.js 26 Apr 2008 20:25:51 -0000
@@ -89,15 +89,7 @@
var scrollY = doc.defaultView.scrollY;
var baseNodeAbsolute = doc.createElementNS("http://www.w3.org/1999/xhtml", "span");
- baseNodeAbsolute.style.backgroundColor = "red";
- baseNodeAbsolute.style.color = "white";
- baseNodeAbsolute.style.position = "absolute";
- baseNodeAbsolute.style.fontSize = "10px";
- baseNodeAbsolute.style.fontWeight = "bold";
- baseNodeAbsolute.style.lineHeight = "10px";
- baseNodeAbsolute.style.padding = "0px 1px 0px 0px";
- baseNodeAbsolute.style.zIndex = "10000001";
- baseNodeAbsolute.style.display = "none";
+ baseNodeAbsolute.style.cssText = liberator.options["hintstyle"];
baseNodeAbsolute.className = "liberator-hint";
var elem, tagname, text, span, rect;
@@ -155,11 +147,44 @@
{
var oldElem = validHints[oldID - 1];
if (oldElem)
- oldElem.style.backgroundColor = "yellow";
+ oldElem.style.backgroundColor = liberator.options["linkbgcolor"];
var newElem = validHints[newID - 1];
if (newElem)
- newElem.style.backgroundColor = "#88FF00";
+ newElem.style.backgroundColor = liberator.options["activelinkbgcolor"];
+ }
+
+ function containsTokensMatcher(str) {
+ var tokens = str.split(/ +/);
+ function containsTokens(str) {
+ for (var i = 0; i < tokens.length; i++) {
+ if (str.indexOf(tokens[i]) < 0)
+ return false;
+ }
+ return true;
+ }
+ return containsTokens;
+ }
+
+ function startsWithMatcher(str) {
+ var regex = new RegExp((str == "" ? ".*" : ("^\\s*" + str + ".*")));
+ function startsWith(str) {
+ return (str.search(regex) == 0);
+ }
+ return startsWith;
+ }
+
+ function hintMatcher(hintString) {
+ var hintMatching = liberator.options["hintmatching"];
+ if (hintMatching == "contains")
+ return containsTokensMatcher(hintString);
+ else if (hintMatching == "startswith")
+ return startsWithMatcher(hintString);
+ else {
+ liberator.echoerr("Invalid hintmatching type: " + hintMatching);
+ return Null;
+ }
+ return Null;
}
function showHints()
@@ -169,11 +194,16 @@
var height = win.innerHeight;
var width = win.innerWidth;
- liberator.log("Show hints matching: " + hintString, 7);
+ liberator.log("Show hints matching: \"" + hintString + "\"", 7);
+
+ var linkfgcolor = liberator.options["linkfgcolor"];
+ var linkbgcolor = liberator.options["linkbgcolor"];
+ var activelinkfgcolor = liberator.options["activelinkfgcolor"];
+ var activelinkbgcolor = liberator.options["activelinkbgcolor"];
var elem, tagname, text, rect, span, imgspan;
var hintnum = 1;
- var findTokens = hintString.split(/ +/);
+ var validHint = hintMatcher(hintString);
var activeHint = hintNumber || 1;
validHints = [];
@@ -193,19 +223,16 @@
span = hints[i][2];
imgspan = hints[i][3];
- for (var k = 0; k < findTokens.length; k++)
+ if (! validHint(text))
{
- if (text.indexOf(findTokens[k]) < 0)
- {
- span.style.display = "none";
- if (imgspan)
- imgspan.style.display = "none";
-
- // reset background color
- elem.style.backgroundColor = hints[i][4];
- elem.style.color = hints[i][5];
- continue outer;
- }
+ span.style.display = "none";
+ if (imgspan)
+ imgspan.style.display = "none";
+
+ // reset background color
+ elem.style.backgroundColor = hints[i][4];
+ elem.style.color = hints[i][5];
+ continue outer;
}
if (text == "" && elem.firstChild && elem.firstChild.tagName == "IMG")
@@ -228,13 +255,13 @@
hints[i][3] = imgspan;
doc.body.appendChild(imgspan);
}
- imgspan.style.backgroundColor = (activeHint == hintnum) ? "#88FF00" : "yellow";
+ imgspan.style.backgroundColor = (activeHint == hintnum) ? activelinkbgcolor : linkbgcolor;
imgspan.style.display = "inline";
}
if (!imgspan)
- elem.style.backgroundColor = (activeHint == hintnum) ? "#88FF00" : "yellow";
- elem.style.color = "black";
+ elem.style.backgroundColor = (activeHint == hintnum) ? activelinkbgcolor : linkbgcolor;
+ elem.style.color = (activeHint == hintnum) ? activelinkfgcolor : linkfgcolor;
span.textContent = "" + (hintnum++);
span.style.display = "inline";
validHints.push(elem);
@@ -420,7 +447,27 @@
validator: function (value) { return value >= 0; }
});
- /////////////////////////////////////////////////////////////////////////////}}}
+ liberator.options.add(["linkfgcolor", "lfc"],
+ "Foreground color of a link during hint mode",
+ "string", "black")
+
+ liberator.options.add(["linkbgcolor", "lbc"],
+ "Background color of a link during hint mode",
+ "string", "yellow")
+
+ liberator.options.add(["activelinkfgcolor", "clfc"],
+ "Foreground color of the current active link during hint mode",
+ "string", "black")
+
+ liberator.options.add(["activelinkbgcolor", "clbc"],
+ "Background color of the current active link during hint mode",
+ "string", "#88FF00")
+
+ liberator.options.add(["hintmatching", "lm"],
+ "How links are matched.",
+ "string", "contains")
+
+ ///////////////////////////////////////////////////////////////////////////
////////////////////// MAPPINGS ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
Index: www/scripts/vimperator.vim
===================================================================
RCS file: /cvs/vimperator/www/scripts/vimperator.vim,v
retrieving revision 1.1
diff -u -r1.1 vimperator.vim
--- www/scripts/vimperator.vim 4 Jan 2008 12:30:32 -0000 1.1
+++ www/scripts/vimperator.vim 26 Apr 2008 20:25:51 -0000
@@ -31,12 +31,14 @@
syn match vimperatorCommandWrapper "\%(!\|\<\h\w*\>\)" contains=vimperatorCommand
syn region vimperatorSet matchgroup=vimperatorCommand start="\<set\=\>" end="$" keepend oneline contains=vimperatorOption
-syn keyword vimperatorOption activate act complete cpt defsearch ds extendedhinttags eht focusedhintstyle fhs fullscreen fs
- \ nofullscreen nofs guioptions go hintchars hc hintstyle hs hinttags ht hlsearch nohlsearch hls nohls hlsearchstyle hlss
- \ incsearch is noincsearch nois ignorecase ic noignorecase noic laststatus ls linksearch nolinksearch lks nolks maxhints
- \ mh more nomore preload nopreload popups pps previewheight pvh scroll scr showmode smd noshowmode nosmd showstatuslinks
- \ ssli showtabline stal smartcase scs nosmartcase noscs titlestring usermode um nousermode noum verbose vbs visualbell vb
- \ novisualbell novb visualbellstyle visualbellstyle t_vb wildmode wim wildoptions wop
+syn keyword vimperatorOption activate act activelinkfgcolor alfc activelinkbgcolor albc complete cpt defsearch ds editor extendedhinttags eht
+ \ focusedhintstyle fhs fullscreen fs nofullscreen nofs guioptions go hintstyle hs hinttags ht hinttimeout hto history hi
+ \ hlsearch hls nohlsearch nohls hlsearchstyle hlss nohlsearchstyle nohlss incsearch is noincsearch nois ignorecase ic
+ \ noignorecase noic insertmode im noinsertmode noim laststatus ls linkbgcolor lbc linkfgcolor lfc linksearch lks linkmatching lm
+ \ nolinksearch nolks more nextpattern nomore pageinfo pa popups pps preload
+ \ nopreload previewheight pvh previouspattern scroll scr showmode smd noshowmode nosmd showstatuslinks ssli showtabline
+ \ stal smartcase scs nosmartcase noscs titlestring usermode um nousermode noum verbose vbs visualbell vb novisualbell novb
+ \ wildmode wim wildoptions wop
\ contained
syn region vimperatorJavascript start="\%(^\s*\%(javascript\|js\)\s\+\)\@<=" end="$" contains=@javascriptTop keepend oneline
More information about the Vimperator
mailing list