mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 06:17:58 +01:00
added better hintmatchers, thanks Daniel
This commit is contained in:
181
content/hints.js
181
content/hints.js
@@ -154,71 +154,6 @@ liberator.Hints = function () //{{{
|
|||||||
newElem.style.backgroundColor = liberator.options["activelinkbgcolor"];
|
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()
|
function showHints()
|
||||||
{
|
{
|
||||||
var startDate = Date.now();
|
var startDate = Date.now();
|
||||||
@@ -451,6 +386,112 @@ liberator.Hints = function () //{{{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hintMatcher(hintString) //{{{
|
||||||
|
{
|
||||||
|
function containsMatcher(hintString) //{{{
|
||||||
|
{
|
||||||
|
var tokens = hintString.split(/ +/);
|
||||||
|
|
||||||
|
function contains(textOfLink)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < tokens.length; i++)
|
||||||
|
{
|
||||||
|
if (textOfLink.indexOf(tokens[i]) < 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return contains;
|
||||||
|
} //}}}
|
||||||
|
|
||||||
|
function wordStartsWithMatcher(hintString, allowWordOverleaping) //{{{
|
||||||
|
{
|
||||||
|
var hintStrings = hintString.split(/ +/);
|
||||||
|
var wordSplitRegex = new RegExp(liberator.options["wordseparators"]);
|
||||||
|
|
||||||
|
function charsAtBeginningOfWords(chars, words, allowWordOverleaping)
|
||||||
|
{
|
||||||
|
var charIdx = 0;
|
||||||
|
for (var wIdx = 0; wIdx < words.length; wIdx++)
|
||||||
|
{
|
||||||
|
var word = words[wIdx];
|
||||||
|
if (word.length == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var prevCharIdx = charIdx;
|
||||||
|
for (var j = 0; j < word.length && charIdx < chars.length; j++, charIdx++)
|
||||||
|
{
|
||||||
|
if (word[j] != chars[charIdx])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prevCharIdx == charIdx && ! allowWordOverleaping)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (charIdx == chars.length)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (charIdx == chars.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringsAtBeginningOfWords(strings, words, allowWordOverleaping)
|
||||||
|
{
|
||||||
|
var strIdx = 0;
|
||||||
|
for (var wIdx = 0; wIdx < words.length; wIdx++)
|
||||||
|
{
|
||||||
|
var word = words[wIdx];
|
||||||
|
if (word.length == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var str = strings[strIdx];
|
||||||
|
if (str.length == 0)
|
||||||
|
strIdx++;
|
||||||
|
else if (word.indexOf(str) == 0)
|
||||||
|
strIdx++;
|
||||||
|
else if (! allowWordOverleaping)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (strIdx == strings.length)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; strIdx < strings.length; strIdx++) {
|
||||||
|
if (strings[strIdx].length != 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (strIdx == strings.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
function wordStartsWith(textOfLink)
|
||||||
|
{
|
||||||
|
if (hintStrings.length == 1 && hintStrings[0].length == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
var words = textOfLink.split(wordSplitRegex);
|
||||||
|
if (hintStrings.length == 1)
|
||||||
|
return charsAtBeginningOfWords(hintStrings[0], words, allowWordOverleaping);
|
||||||
|
else
|
||||||
|
return stringsAtBeginningOfWords(hintStrings, words, allowWordOverleaping);
|
||||||
|
}
|
||||||
|
|
||||||
|
return wordStartsWith;
|
||||||
|
} //}}}
|
||||||
|
|
||||||
|
var hintMatching = liberator.options["hintmatching"];
|
||||||
|
switch (hintMatching)
|
||||||
|
{
|
||||||
|
case "contains" : return containsMatcher(hintString);
|
||||||
|
case "wordstartswith": return wordStartsWithMatcher(hintString, /*allowWordOverleaping=*/ true);
|
||||||
|
case "firstletters" : return wordStartsWithMatcher(hintString, /*allowWordOverleaping=*/ false);
|
||||||
|
default : liberator.echoerr("Invalid hintmatching type: " + hintMatching);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} //}}}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
////////////////////// OPTIONS /////////////////////////////////////////////////
|
////////////////////// OPTIONS /////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
@@ -495,14 +536,18 @@ liberator.Hints = function () //{{{
|
|||||||
"Background color of the current active link during hint mode",
|
"Background color of the current active link during hint mode",
|
||||||
"string", "#88FF00");
|
"string", "#88FF00");
|
||||||
|
|
||||||
liberator.options.add(["hintmatching", "lm"],
|
liberator.options.add(["hintmatching", "hm"],
|
||||||
"How links are matched",
|
"How links are matched",
|
||||||
"string", "contains",
|
"string", "contains",
|
||||||
{
|
{
|
||||||
validator: function (value) { return /^startswith|contains|wordboundary$/.test(value); }
|
validator: function (value) { return /^contains|wordstartswith|firstletters$/.test(value); }
|
||||||
});
|
});
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
liberator.options.add(["wordseparators", "wsp"],
|
||||||
|
"How words are splitted for hintmatching",
|
||||||
|
"string", '[\\.,!\\?:;/\\\"\\^\\$%&§\\(\\)\\[\\]\\{\\}<>#\\*\\+\\|=~ _\\-]');
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
|
|||||||
@@ -214,11 +214,21 @@ ____
|
|||||||
|
|
||||||
Change the hint matching algorithm during hint mode. Possible values:
|
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.
|
*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.
|
*wordstartswith* The typed characters are matched with the beginning of the first word (see 'wordseparators') in the link as long as possible. If no more or no character matches in the current word, than the matching is continued at the beginning of the next word. The words are worked through in the order they appear in the link. If the typed characters contain spaces, than the characters are splitted by spaces. These character groups are than matched with the beginning of the words, beginning at the first one and continuing with the following words in the order they appear in the link.
|
||||||
*startswith* The typed characters have to be in the typed order at the beginning of the text of the link.
|
*firstletters* Behaves almost as wordstartswith, but non matching words aren't overleaped.
|
||||||
----------------------------------------------------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
____
|
||||||
|
|
||||||
|
|\'wsp'| |\'wordseparators'|
|
||||||
|
||'wordseparators' 'wsp'|| string (default: [\.,!\?:;/\\"\^\$%&§\(\)\[\]\\{\\}<>#\\*\+\\|=~ _\\-])
|
||||||
|
____
|
||||||
|
|
||||||
|
A regex which defines the word separators which are used for the 'hintmatching' types
|
||||||
|
'wordstartswith' and 'firstletters' to split the words in the text of a link. +
|
||||||
|
NOTE: Because 'wordseparators' is a string, each backspace has to be quoted by another backspace.
|
||||||
|
|
||||||
____
|
____
|
||||||
|
|
||||||
@@ -361,7 +371,7 @@ The possible values:
|
|||||||
____
|
____
|
||||||
|
|
||||||
|\'nextpattern'|
|
|\'nextpattern'|
|
||||||
||'nextpattern'|| stringlist (default: \bnext,^>$,^(>>|»)$,^(>|»),(>|»)$,\bmore\b)
|
||'nextpattern'|| stringlist (default: \bnext,^>$,^(>>|»)$,^(>|»),(>|»)$,\bmore\b)
|
||||||
____
|
____
|
||||||
Patterns to use when guessing the 'next' page in a document sequence.
|
Patterns to use when guessing the 'next' page in a document sequence.
|
||||||
Each pattern, in order, is matched against all links in the page with the first match being used.
|
Each pattern, in order, is matched against all links in the page with the first match being used.
|
||||||
@@ -423,7 +433,7 @@ ____
|
|||||||
// 'pvh'
|
// 'pvh'
|
||||||
|
|
||||||
|\'previouspattern'|
|
|\'previouspattern'|
|
||||||
||'previouspattern'|| stringlist (default: \bprev|previous\b,^<$,^(<<|«)$,^(<|«),(<|«)$)
|
||'previouspattern'|| stringlist (default: \bprev|previous\b,^<$,^(<<|«)$,^(<|«),(<|«)$)
|
||||||
____
|
____
|
||||||
Patterns to use when guessing the 'previous' page in a document sequence
|
Patterns to use when guessing the 'previous' page in a document sequence
|
||||||
Each pattern, in order, is matched against all links in the page with the first match being used.
|
Each pattern, in order, is matched against all links in the page with the first match being used.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ syn keyword vimperatorOption activate act activelinkfgcolor alfc activelinkbgcol
|
|||||||
\ nolinksearch nolks more nextpattern nomore pageinfo pa popups pps preload
|
\ nolinksearch nolks more nextpattern nomore pageinfo pa popups pps preload
|
||||||
\ nopreload previewheight pvh previouspattern scroll scr showmode smd noshowmode nosmd showstatuslinks ssli showtabline
|
\ 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
|
\ stal smartcase scs nosmartcase noscs titlestring usermode um nousermode noum verbose vbs visualbell vb novisualbell novb
|
||||||
\ wildmode wim wildoptions wop
|
\ wildmode wim wildoptions wop wordseparators wsp
|
||||||
\ contained
|
\ contained
|
||||||
|
|
||||||
syn region vimperatorJavascript start="\%(^\s*\%(javascript\|js\)\s\+\)\@<=" end="$" contains=@javascriptTop keepend oneline
|
syn region vimperatorJavascript start="\%(^\s*\%(javascript\|js\)\s\+\)\@<=" end="$" contains=@javascriptTop keepend oneline
|
||||||
|
|||||||
Reference in New Issue
Block a user