Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

prevent bubbling of escape key #2713

Merged
merged 4 commits into from
Oct 11, 2016
Merged

prevent bubbling of escape key #2713

merged 4 commits into from
Oct 11, 2016

Conversation

koenpunt
Copy link
Collaborator

@koenpunt koenpunt commented Oct 2, 2016

When the results are showing, pressing escape only hides the results, and then prevents bubbling.

Also introduced an extra method to retrieve the search input value, so that the keydown_checker can be moved to the abstract class.
This method can also be used as an additional solution for #2370, e.g.:

$('.chosen').chosen().on('chosen:no_results', function(event, data) {
  console.log(data.chosen.get_search_field_value());
});

fixes #1256
fixes #2653

@koenpunt koenpunt changed the title prevent bubbling of escape prevent bubbling of escape key Oct 2, 2016
return true
when 9, 38, 40, 16, 91, 17, 18
break
when 9, 16, 17, 18, 38, 40, 91
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My hero.

if @is_multiple and @backstroke_length < 1 and this.choices_count() > 0
this.keydown_backstroke()
else if not @pending_backstroke
this.result_clear_highlight()
this.results_search()
when 13
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to add all of these explicit breaks here; CoffeeScript handles that.

Docs:

Switch statements in JavaScript are a bit awkward. You need to remember to break at the end of every case statement to avoid accidentally falling through to the default case. CoffeeScript prevents accidental fall-through...

Confirmed with the "Try CoffeeScript" dingus on http://coffeescript.org/ as well.

Copy link
Collaborator Author

@koenpunt koenpunt Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but if you don't add them, CoffeeScript returns a value, and I wanted to get rid of the return true below, so for consistency I added it everywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Fair enough.

switch stroke
when 8 # backspace
@backstroke_length = this.get_search_field_value().length
break
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on all of these breaks — can be safely removed.

@tjschuck
Copy link
Member

tjschuck commented Oct 4, 2016

The biggest question I had that came out of reviewing this is WTF a backstroke is, but it looks like that name was added in the initial commit 😮 by @pfiller

👍 on this one, though!

@koenpunt koenpunt merged commit 36c0617 into harvesthq:master Oct 11, 2016
@koenpunt koenpunt deleted the escape branch October 11, 2016 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants