Skip to content

Commit

Permalink
removed .test() in favor of .exec(), separated search match function
Browse files Browse the repository at this point in the history
  • Loading branch information
koenpunt committed Jul 28, 2017
1 parent b9500e0 commit 21fa001
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class AbstractChosen

option.search_match = false
results_group = null
search_match = null

if this.include_option_in_results(option)

Expand All @@ -187,14 +188,14 @@ class AbstractChosen
option.search_text = if option.group then option.label else option.html

unless option.group and not @group_search
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) + '</em>' + option.search_text.substr(startpos + searchText.length)
option.search_text = text.substr(0, startpos) + '<em>' + text.substr(startpos)

Expand All @@ -217,6 +218,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?

Expand Down

0 comments on commit 21fa001

Please sign in to comment.