Skip to content

Commit

Permalink
Refactor option.search_text to be a local variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Arun Srinivasan committed Aug 22, 2017
1 parent 475a808 commit 07e5179
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,20 @@ class AbstractChosen
results += 1 if results_group.active_options is 0 and results_group.search_match
results_group.active_options += 1

option.search_text = if option.group then option.label else option.text
text = if option.group then option.label else option.text

unless option.group and not @group_search
search_match = this.search_string_match(option.search_text, regex)
search_match = this.search_string_match(text, regex)
option.search_match = search_match?

results += 1 if option.search_match and not option.group


if option.search_match
if query.length
startpos = search_match.index
prefix = option.search_text.slice(0, startpos)
fix = option.search_text.slice(startpos, startpos + query.length)
suffix = option.search_text.slice(startpos + query.length)
prefix = text.slice(0, startpos)
fix = text.slice(startpos, startpos + query.length)
suffix = text.slice(startpos + query.length)
option.highlighted_html = "#{this.escape_html(prefix)}<em>#{this.escape_html(fix)}</em>#{this.escape_html(suffix)}"

results_group.group_match = true if results_group?
Expand Down

0 comments on commit 07e5179

Please sign in to comment.