Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Abstracted get_search_regex for future testing #1823

Merged
merged 1 commit into from
Mar 12, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down