diff --git a/coffee/lib/abstract-chosen.coffee b/coffee/lib/abstract-chosen.coffee index b22bd00a763..4bb7b39933c 100644 --- a/coffee/lib/abstract-chosen.coffee +++ b/coffee/lib/abstract-chosen.coffee @@ -137,6 +137,7 @@ class AbstractChosen option.search_match = false results_group = null + search_match = null if this.include_option_in_results(option) @@ -152,14 +153,14 @@ class AbstractChosen unless option.group and not @group_search option.search_text = if option.group then option.label else option.text - option.search_match = regex.test(option.search_text) + search_match = this.search_string_match(option.search_text, regex) + option.search_match = search_match? results += 1 if option.search_match and not option.group if option.search_match if searchText.length - match = regex.exec(option.search_text) - startpos = match.index + startpos = search_match.index text = option.search_text.substr(0, startpos + searchText.length) + '' + option.search_text.substr(startpos + searchText.length) option.search_text = text.substr(0, startpos) + '' + text.substr(startpos) @@ -182,6 +183,9 @@ class AbstractChosen regex_string = "^#{regex_string}" unless @enable_split_word_search or @search_contains new RegExp(regex_string, 'i') + search_string_match: (search_string, regex) -> + regex.exec(search_string) + choices_count: -> return @selected_option_count if @selected_option_count?