From 3c4edd335b0af8242fa203e0b531d1d1d42ed7e1 Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Wed, 30 Apr 2008 21:45:36 +0000 Subject: [PATCH] added new hint color options and a new hintmatching option (thanks Daniel) --- AUTHORS | 1 + Makefile.common | 2 +- content/hints.js | 146 ++++++++++++++++++++++++++++++--------- content/mail.js | 22 +++++- content/muttator.js | 2 +- locale/en-US/options.txt | 50 ++++++++++++-- vimperator.vim | 19 ++--- 7 files changed, 192 insertions(+), 50 deletions(-) diff --git a/AUTHORS b/AUTHORS index ae8946ae..8c0b1bc7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,6 +11,7 @@ Inactive/former developers: * Viktor Kojouharov (Виктор Кожухаров) Patches (in no special order): + * Daniel Trstenjak (various things with hints) * M.Terada (suggest engines) * Muthu Kannan (ctrl-v support) * Lars Kindler (:buffer(s) functionality) diff --git a/Makefile.common b/Makefile.common index 717e7a7e..408f7290 100644 --- a/Makefile.common +++ b/Makefile.common @@ -8,7 +8,7 @@ DOC_SRC_FILES = $(wildcard locale/*/*.txt) DOC_FILES = ${DOC_SRC_FILES:%.txt=%.html} # TODO: specify source files manually? -JAR_TXT_FILES = ${shell find content skin locale \ +JAR_TXT_FILES = ${shell find -L content skin locale \ -type f \ -a ! -path '*CVS*' \ -a \( \ diff --git a/content/hints.js b/content/hints.js index 163132ae..85cdc904 100644 --- a/content/hints.js +++ b/content/hints.js @@ -89,15 +89,7 @@ liberator.Hints = function () //{{{ 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,76 @@ liberator.Hints = function () //{{{ { 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(hintString) + { + var tokens = hintString.split(/ +/); + + function containsTokens(textOfLink) + { + for (var i = 0; i < tokens.length; i++) + { + if (textOfLink.indexOf(tokens[i]) < 0) + return false; + } + + return true; + } + + return containsTokens; + } + + function wordBoundaryMatcher(hintString) + { + var tokens = hintString.split(/ +/); + var regexs = []; + for (var i = 0; i < tokens.length; i++) + regexs[i] = new RegExp((tokens[i] == "" ? ".*" : ("\\b" + tokens[i] + ".*"))); + + function wordBoundary(textOfLink) + { + for (var i = 0; i < tokens.length; i++) + { + if (! regexs[i].test(textOfLink)) + return false; + } + + return true; + } + + return wordBoundary; + } + + function startsWithMatcher(hintString) + { + var regex = new RegExp((hintString == "" ? ".*" : ("^\\s*" + hintString + ".*"))); + + function startsWith(textOfLink) + { + return (regex.test(textOfLink)); + } + + return startsWith; + } + + function hintMatcher(hintString) + { + var hintMatching = liberator.options["hintmatching"]; + switch (hintMatching) + { + case "contains": return containsTokensMatcher(hintString); + case "startswith": return startsWithMatcher(hintString); + case "wordboundary": return wordBoundaryMatcher(hintString); + default: + liberator.echoerr("Invalid hintmatching type: " + hintMatching); + } + return null; } function showHints() @@ -169,11 +226,16 @@ liberator.Hints = function () //{{{ 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 +255,16 @@ liberator.Hints = function () //{{{ 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"; + 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; - } + // 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 +287,13 @@ liberator.Hints = function () //{{{ 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); @@ -404,15 +463,15 @@ liberator.Hints = function () //{{{ liberator.options.add(["extendedhinttags", "eht"], "XPath string of hintable elements activated by ';'", "string", DEFAULT_HINTTAGS); - liberator.options.add(["focusedhintstyle", "fhs"], - "CSS specification of focused hints", - "string", "z-index:5000; font-family:monospace; font-size:12px; color:ButtonText; background-color:ButtonShadow; border-color:ButtonShadow; border-width:1px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;"); + liberator.options.add(["hintstyle", "hs"], "CSS specification of unfocused hints", - "string", "z-index:5000; font-family:monospace; font-size:12px; color:white; background-color:red; border-color:ButtonShadow; border-width:0px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;"); + "string", "z-index:5000; font-family:monospace; font-size:10px; font-weight: bold; color:white; background-color:red; border-color:ButtonShadow; border-width:0px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;"); + liberator.options.add(["hinttags", "ht"], "XPath string of hintable elements activated by 'f' and 'F'", "string", DEFAULT_HINTTAGS); + liberator.options.add(["hinttimeout", "hto"], "Automatically follow non unique numerical hint", "number", 0, @@ -420,7 +479,30 @@ liberator.Hints = function () //{{{ 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", "alfc"], + "Foreground color of the current active link during hint mode", + "string", "black"); + + liberator.options.add(["activelinkbgcolor", "albc"], + "Background color of the current active link during hint mode", + "string", "#88FF00"); + + liberator.options.add(["hintmatching", "lm"], + "How links are matched", + "string", "contains", + { + validator: function (value) { return /^startswith|contains|wordboundary$/.test(value); } + }); + + /////////////////////////////////////////////////////////////////////////// ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ diff --git a/content/mail.js b/content/mail.js index 45068019..861b0ae2 100644 --- a/content/mail.js +++ b/content/mail.js @@ -202,9 +202,25 @@ liberator.Mail = function () function () { goDoCommand("cmd_forwardInline"); }); - liberator.mappings.add(modes, ["r"], - "Reply to sender", - function () { goDoCommand("cmd_reply"); }); + // UNDO/REDO + liberator.mappings.add(modes, ["u"], + "Undo", + function () + { + if (messenger.canUndo()) + messenger.undo(msgWindow); + else + liberator.beep(); + }); + liberator.mappings.add(modes, [""], + "Redo", + function () + { + if (messenger.canRedo()) + messenger.redo(msgWindow); + else + liberator.beep(); + }); // GETTING MAIL liberator.mappings.add(modes, ["gm"], diff --git a/content/muttator.js b/content/muttator.js index 2ca2b317..f3e91924 100644 --- a/content/muttator.js +++ b/content/muttator.js @@ -89,7 +89,7 @@ liberator.config = { function () { liberator.commandline.open(":", "open ", liberator.modes.EX); }); // don't wait too long when selecting new messages - GetThreadTree()._selectDelay = 250; // TODO: make configurable + GetThreadTree()._selectDelay = 300; // TODO: make configurable } } diff --git a/locale/en-US/options.txt b/locale/en-US/options.txt index 3acbd0cc..e9311b21 100644 --- a/locale/en-US/options.txt +++ b/locale/en-US/options.txt @@ -172,12 +172,54 @@ or @oncommand or @class='lk' or @class='s'] | The XPath string of hintable elements activated by [m];[m]. ____ -|\'fhs'| |\'focusedhintstyle'| -||'focusedhintstyle' 'fhs'|| string +|\'hs'| |\'hintstyle'| +||'hintstyle' 'hs'|| string ____ -(default: z-index:5000; font-family:monospace; font-size:12px; color:ButtonText; background-color:ButtonShadow; border-color:ButtonShadow; border-width:1px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;) +(default: z-index:5000; font-family:monospace; font-size:12px; color:white; background-color:red; border-color:ButtonShadow; border-width:0px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;) + +CSS specification of hints +____ + +|\'lfc'| |\'linkfgcolor'| +||'linkfgcolor' 'lfc'|| string (default: black) +____ + +Foreground color of a link during hint mode. +____ + +|\'lbc'| |\'linkbgcolor'| +||'linkbgcolor' 'lbc'|| string (default: yellow) +____ + +Background color of a link during hint mode. +____ + +|\'alfc'| |\'activelinkfgcolor'| +||'activelinkfgcolor' 'alfc'|| string (default: black) +____ + +Foreground color of the current active link during hint mode. +____ + +|\'albc'| |\'activelinkbgcolor'| +||'activelinkbgcolor' 'albc'|| string (default: ##88FF00) +____ + +Background color of the current active link during hint mode. +____ + +|\'hm'| |\'hintmatching'| +||'hintmatching' 'hm'|| string (default: contains) +____ + +Change the hint matching algorithm during hint mode. Possible values: + +`--------------`------------------------------------------------------------------------------------------------------------------------ +*contains* The typed characters are splitted by spaces, and these character groups have to be anywhere inside the text of the link. +*wordboundary* The typed characters are splitted by spaces, and these character groups must each match the start of a word of the link. +*startswith* The typed characters have to be in the typed order at the beginning of the text of the link. +---------------------------------------------------------------------------------------------------------------------------------------- -CSS specification of focused hints ____ |\'nofs'| |\'nofullscreen'| |\'fs'| |\'fullscreen'| diff --git a/vimperator.vim b/vimperator.vim index fecef63d..aba3dbf0 100644 --- a/vimperator.vim +++ b/vimperator.vim @@ -38,14 +38,15 @@ syn match vimperatorCommand "!" contained syn match vimperatorCommandWrapper "\%(^\s*:\=\)\@<=\%(!\|\h\w*\>\)" contains=vimperatorCommand syn region vimperatorSet matchgroup=vimperatorCommand start="\%(^\s*:\=\)\@<=\" 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 - \ 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 keyword vimperatorOption activate act activelinkfgcolor alfc activelinkbgcolor albc complete cpt defsearch ds editor extendedhinttags eht + \ fullscreen fs nofullscreen nofs guioptions go hintmatching hm 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 syn region vimperatorJavascript matchgroup=vimperatorJavascriptDelimiter @@ -70,4 +71,4 @@ let b:current_syntax = "vimperator" let &cpo = s:cpo_save unlet s:cpo_save -" vim: tw=130: +" vim: tw=130 et ts=4 sw=4: