-
-
Notifications
You must be signed in to change notification settings - Fork 277
refactor/bugfix: Migrate keypress to using commands instead of hardcoded keys. #953
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
Changes from all commits
351b45f
7f29955
858bf4c
7b11404
b810ef7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
KEY_BINDINGS, | ||
is_command_key, | ||
keys_for_command, | ||
primary_key_for_command, | ||
) | ||
from zulipterminal.config.symbols import ( | ||
CHECK_MARK, | ||
|
@@ -165,10 +166,10 @@ def mouse_event( | |
) -> bool: | ||
if event == "mouse press": | ||
if button == 4: | ||
self.keypress(size, "up") | ||
self.keypress(size, primary_key_for_command("GO_UP")) | ||
return True | ||
if button == 5: | ||
self.keypress(size, "down") | ||
self.keypress(size, primary_key_for_command("GO_DOWN")) | ||
return True | ||
return super().mouse_event(size, event, button, col, row, focus) | ||
|
||
|
@@ -200,15 +201,15 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]: | |
|
||
elif is_command_key("SCROLL_UP", key) and not self.old_loading: | ||
if self.focus is not None and self.focus_position == 0: | ||
return self.keypress(size, "up") | ||
return self.keypress(size, primary_key_for_command("GO_UP")) | ||
else: | ||
return super().keypress(size, "page up") | ||
return super().keypress(size, primary_key_for_command("SCROLL_UP")) | ||
|
||
elif is_command_key("SCROLL_DOWN", key) and not self.old_loading: | ||
if self.focus is not None and self.focus_position == len(self.log) - 1: | ||
return self.keypress(size, "down") | ||
return self.keypress(size, primary_key_for_command("GO_DOWN")) | ||
else: | ||
return super().keypress(size, "page down") | ||
return super().keypress(size, primary_key_for_command("SCROLL_DOWN")) | ||
neiljp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
elif is_command_key("THUMBS_UP", key): | ||
if self.focus is not None: | ||
|
@@ -365,10 +366,10 @@ def mouse_event( | |
) -> bool: | ||
if event == "mouse press": | ||
if button == 4: | ||
self.keypress(size, "up") | ||
self.keypress(size, primary_key_for_command("GO_UP")) | ||
return True | ||
elif button == 5: | ||
self.keypress(size, "down") | ||
self.keypress(size, primary_key_for_command("GO_DOWN")) | ||
return True | ||
return super().mouse_event(size, event, button, col, row, focus) | ||
|
||
|
@@ -474,10 +475,10 @@ def mouse_event( | |
) -> bool: | ||
if event == "mouse press": | ||
if button == 4: | ||
self.keypress(size, "up") | ||
self.keypress(size, primary_key_for_command("GO_UP")) | ||
return True | ||
elif button == 5: | ||
self.keypress(size, "down") | ||
self.keypress(size, primary_key_for_command("GO_DOWN")) | ||
return True | ||
return super().mouse_event(size, event, button, col, row, focus) | ||
|
||
|
@@ -514,11 +515,11 @@ def mouse_event( | |
return True | ||
if button == 4: | ||
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")) | ||
Comment on lines
517
to
+522
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
return super().mouse_event(size, event, button, col, row, focus) | ||
|
||
|
||
|
@@ -574,8 +575,8 @@ def update_message_list_status_markers(self) -> None: | |
|
||
def keypress(self, size: urwid_Size, key: str) -> Optional[str]: | ||
if is_command_key("GO_BACK", key): | ||
self.header.keypress(size, "esc") | ||
self.footer.keypress(size, "esc") | ||
self.header.keypress(size, key) | ||
self.footer.keypress(size, key) | ||
self.set_focus("body") | ||
|
||
elif self.focus_position in ["footer", "header"]: | ||
|
@@ -587,14 +588,14 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]: | |
return key | ||
|
||
elif is_command_key("REPLY_MESSAGE", key): | ||
self.body.keypress(size, "enter") | ||
self.body.keypress(size, key) | ||
Comment on lines
590
to
+591
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? 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 commentThe 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. |
||
if self.footer.focus is not None: | ||
self.set_focus("footer") | ||
self.footer.focus_position = 1 | ||
return key | ||
|
||
elif is_command_key("STREAM_MESSAGE", key): | ||
self.body.keypress(size, "c") | ||
self.body.keypress(size, key) | ||
# For new streams with no previous conversation. | ||
if self.footer.focus is None: | ||
stream_id = self.model.stream_id | ||
|
@@ -605,7 +606,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]: | |
return key | ||
|
||
elif is_command_key("REPLY_AUTHOR", key): | ||
self.body.keypress(size, "R") | ||
self.body.keypress(size, key) | ||
if self.footer.focus is not None: | ||
self.set_focus("footer") | ||
self.footer.focus_position = 1 | ||
|
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.