From 29261ca9f64ae5d2087a47b3a02ed8631277d582 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 12 Mar 2014 11:27:19 +0100 Subject: [PATCH] Abstracted get_search_regex for future testing --- coffee/lib/abstract-chosen.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/coffee/lib/abstract-chosen.coffee b/coffee/lib/abstract-chosen.coffee index e4a3c8d555f..c6adaf61ea2 100644 --- a/coffee/lib/abstract-chosen.coffee +++ b/coffee/lib/abstract-chosen.coffee @@ -131,9 +131,8 @@ class AbstractChosen searchText = this.get_search_text() escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") - regexAnchor = if @search_contains then "" else "^" - regex = new RegExp(regexAnchor + escapedSearchText, 'i') zregex = new RegExp(escapedSearchText, 'i') + regex = this.get_search_regex(escapedSearchText) for option in @results_data @@ -177,6 +176,10 @@ class AbstractChosen this.update_results_content this.results_option_build() this.winnow_results_set_highlight() + get_search_regex: (escaped_search_string) -> + regex_anchor = if @search_contains then "" else "^" + new RegExp(regex_anchor + escaped_search_string, 'i') + search_string_match: (search_string, regex) -> if regex.test search_string return true