-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
refactor/bugfix: Migrate keypress to using commands instead of hardcoded keys. #953
Conversation
@zulipbot add "PR needs review" |
5c3c996
to
6166a46
Compare
6166a46
to
9b40ecb
Compare
9b40ecb
to
519be4d
Compare
a72b18e
to
a0d2a70
Compare
Not sure if I should call the 4th commit a bugfix, since there is no bug currently but there might be if we tried to customize the keys, which sounds like an (indirect) bug?? |
a0d2a70
to
6aebb49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zee-bit I had this half-reviewed before I was away but apparently didn't send it, so here's some feedback - this will tidy up the last of the keypress refactoring 👍
I think my only concern here is potential interactions with how we're handling standard movements that urwid expects, which @Rohitth007 is looking into with the urwid command-map. We can discuss and check again before merging in any case.
tests/ui/test_ui_tools.py
Outdated
"scroll_wheel_down", | ||
], | ||
) | ||
def test_mouse_event(self, mocker, topic_view, button, key, widget_size): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add this in a separate commit - otherwise this isn't a pure refactor. Will that leave it the same as Preet's original commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, adding that in a separate commit would leave it the same as Preet's commit. Do you want me to put that in a separate commit or just reword the commit message to not indicate it's a pure refactor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, added it as a separate commit. :)
for _ in range(5): | ||
self.keypress(size, "up") | ||
self.keypress(size, primary_key_for_command("GO_UP")) | ||
return True | ||
elif button == 5: | ||
for _ in range(5): | ||
self.keypress(size, "down") | ||
self.keypress(size, primary_key_for_command("GO_DOWN")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this refactor, but while mouse access is not a priority the 5x multiplier isn't consistent with the other boxes. I'd like this to be consistent, but equally I don't use a scroll-wheel mouse right now, so we can discuss in the stream.
I think this might have been brought up recently in discussion, but I'm not sure we reached a conclusion?
@@ -1516,15 +1516,15 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]: | |||
recipient_user_ids=[self.message["sender_id"]], | |||
) | |||
elif is_command_key("MENTION_REPLY", key): | |||
self.keypress(size, "enter") | |||
self.keypress(size, primary_key_for_command("REPLY_MESSAGE")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes in this file likely work in practice, but mainly since we going through the intermediary of a str
. At least, that's my perception of what's happening - can you see what I mean? We may want to make another change in this file to give these changes proper meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really sorry, but I don't get this. Could you please explain a bit more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually was broken at this commit - there was no REPLY_MESSAGE handler for this and manual testing confirmed issues. Compare the difference between your local version and the version I pushed.
elif is_command_key("REPLY_MESSAGE", key): | ||
self.body.keypress(size, "enter") | ||
self.body.keypress(size, key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is the start point you're referring to in the commit text?
So REPLY_MESSAGE here -> "enter" on box -> behavior like REPLY_MESSAGE via "ENTER" filter ?
This is a good find, but the commit text could be improved to make this clearer - what file/class source triggers what other ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this, but as noted I adjusted code between the last two commits to make this a little more accurate.
I don't think these changes would have interfere with the keypress PR. It's just that some of these keypress calls are no longer needed. I could rebase on top of these changes. |
6aebb49
to
368f03e
Compare
368f03e
to
7058835
Compare
This adds a fixture that generates the required parameters for mouse scroll actions. We return the type of event i.e. mouse press, along with the button and the expected key to be triggered for this mouse_event. Introducing the mouse_scroll_event fixture in mouse_event tests for several *Views classes reduces code duplication - essentially extracting duplicated test code and parametrizes into one fixture, making the tests more compact and readable. Co-authored-by: Preet Mishra <ipreetmishra@gmail.com>
Adds missing mouse_event test in TestTopicView class to increase our scope of testing and maintain consistency with other similar classes.
This commit migrates mouse_event functions to use primary_key_for_commands instead of hard-coded keys to ensure that they are resistant to breakage if navigational keys are updated in future. Tests amended.
The 'r' key that is used to reply to a message was actually depending on 'enter' key for its functionality. When replying to a message, the keypress is first intercepted by MiddleColumnView as part of REPLY_MESSAGE command, which is passed to the corresponding MessageBox as "enter" keypress. The MessageBox grabs this key and executes message reply but via the ENTER filter. This commit makes 'r' key for replying to message independent of 'enter' by passing the command 'REPLY_MESSAGE' instead of the hardcoded 'enter' key to MessageBox. Tests amended. Balance of code between commits adjusted slightly for correctness by neiljp.
This commit replaces all instances of hard-coded keys passed to keypress that posed a risk of breaking tests if in future we tried to customize the keys. Instead of passing keys we pass their corresponding commands that is more flexible and resistant to breakage on changing keys. Tests amended.
7058835
to
b810ef7
Compare
Hello @zee-bit, it seems like you have referenced #469 in your pull request description, but you have not referenced them in your commit message description(s). When you reference an issue in a commit message, it automatically closes the corresponding issue when the commit is merged. Please run An example of a correctly-formatted commit:
Thank you for your contributions to Zulip! |
@zee-bit This was essentially in a mergeable state except for a few points - I squashed the first two commits together (they make a refactor together), moved & slightly adjusted some code between the last two commits for correctness, and reordered them so that the "replace hardcoded key" statement remains correct - now to merge 🎉 |
Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out! |
This PR aims to replace all hard-coded keys in keypress to use their corresponding commands, to make them future-proof.
Commit flow:
TopicsView
.primary_key_for_commands
.r
for replying to message independent ofENTER
key.Our codebase would have no instances of hard-coded keys now. Can be checked using:
git grep keypress\(size
Fixes #469 and #533.