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

typeahead: Properly handle custom triggers. #14247

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aero31aero
Copy link
Member

@aero31aero aero31aero commented Mar 19, 2020

Fixes #14246.

This fixes an issue in our stream-topic typeahead code where sometimes typing #den> wouldn't complete the stream mention.

I've added the second commit here to run tests properly.

@showell
Copy link
Contributor

showell commented Mar 20, 2020

I wonder if this would actually be more maintainable if we just used undefined for this.custom_selection_state rather than having to give falsy values (of three different types!) for the three fields.

I would also make the commenting here slightly more verbose, as it's hard for somebody jumping in this code to know what's going on.

The variable name custom_selection_state is possibly confusing me here, because when I hear "selection" I think copy/paste instead of choosing, and I think this is more about choosing, correct?

@showell
Copy link
Contributor

showell commented Mar 20, 2020

I guess "selection" is already well explained in the big block comment (which I didn't see in the diff), so disregard that part of my prior comment.

@aero31aero aero31aero force-pushed the 3-typeahead-issues branch 2 times, most recently from 7a1cf13 to 6adc639 Compare March 20, 2020 21:04
@aero31aero
Copy link
Member Author

I was on the fence for using selection here, but the typeahead function is called this.select() so it made sense to follow the convention and say trigger_selection. Anyway, updated the default to be an empty object. This avoids having to write code like if (this.x and this.x.y) and also avoids having to specify any defaults.

I would also make the commenting here slightly more verbose, as it's hard for somebody jumping in this code to know what's going on.

This is why I added a reference to the issue where I've written a larger write-up. Since the write-up was large enough, I figured it made sense to have it in a rendered markdown format instead of an in-file comment. (#14246).

To make sure people stumble on it, I added the comment at the top of the file as well now.

@@ -352,7 +368,8 @@
break

default:
if (this.trigger_selection(e)) {
if (this.custom_selection_state.should_trigger) {
this.custom_selection_state.should_trigger = false;
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This code is kinda hard to follow. Are we confident that this.custom_selection_state is always set during a keyup call? And is the keyCode in custom_selection_state used for anything?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, a keyup event implies that we have already had a keypress event.

We switch to using keypress event for custom triggers because keyup can be
tricky to handle for combo keys. If you press 'shift' + '.', you get >
However, we never get the keyup event for '>'. Instead, we get one
for '.' and one for 'shift'. If you check the e.key value, depending
on whether shift was released first or later, we can get either '.' or '>'.

Fixes zulip#14246.
@zulipbot
Copy link
Member

zulipbot commented Feb 3, 2022

Heads up @aero31aero, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

typeahead: Properly handle custom triggers.
4 participants