Skip to content

Commit 0f9253a

Browse files
author
Bas van den Heuvel
committed
Added comments to fuzzy matcher
1 parent 5c482ee commit 0f9253a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

common/content/hints.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,24 @@ const Hints = Module("hints", {
833833
};
834834
} //}}}
835835

836+
/**
837+
* Get a hint matcher for hintmatching=fuzzy
838+
*
839+
* The user input can be anything. The matcher looks for occurances of
840+
* the characters in the user input. If all occurances are found in the
841+
* link, in order, the link is relevant.
842+
*
843+
* @param {string} hintString The string typed by the user.
844+
* @returns {function(string):boolean} A function that takes the text
845+
* of a hint and returns true if all characters of the input are
846+
* found in the link.
847+
*/
836848
function fuzzyMatcher(hintString) {
837849
expression = '';
838850

851+
// Build a regex for fuzzy matching with the input.
852+
//
853+
// If the input is 'abc', the regex will be '[^a]*a[^b]*b[^c]c'.
839854
for (var i = 0; i < hintString.length; i ++) {
840855
var char = hintString[i];
841856
expression += '[^' + char + ']*' + char;

0 commit comments

Comments
 (0)