From 687483f3130e1513c06e547b4a72311e5c15d424 Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Tue, 28 Feb 2017 11:26:56 +0000 Subject: [PATCH] Add regex test to main Just playing with various autocomplete options --- addon/src/main.litcoffee | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addon/src/main.litcoffee b/addon/src/main.litcoffee index ee75b84d..d4d29f83 100644 --- a/addon/src/main.litcoffee +++ b/addon/src/main.litcoffee @@ -78,6 +78,19 @@ The following functions all talk to the content.js script to perform functions t browser.browserAction.onClicked.addListener(handleBrowserAction) +## Regex test + +Adapted from http://www.dustindiaz.com/autocomplete-fuzzy-matching + + tridactyl.mystrings = mystrings = ["colin", "olie", "jake", "harri"] + tridactyl.func.matchString = matchString = (input) -> + search = new RegExp(input.split('').join('\\w*').replace(/\W/, ""), 'i') + mystrings.filter((string) -> + if string.match(search) + return string + ) + + ## Finish the Tridactyl namespace and initialise it tridactyl.func.__init__()