-
-
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
boxes: Disable cycling using arrow keys if recipient is invalid. #864
base: main
Are you sure you want to change the base?
Conversation
834b1ae
to
67d5df8
Compare
@zee-bit Just some quick feedback:
|
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.
@neiljp Regarding your feedback:
|
@zulipbot add "PR needs review" |
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 This needs rebasing to work around conflicts and potentially update for the latest improvements in the PM UI/data, but the implementation also demonstrates both the duplication and what look like issues due to not duplicating extra code. This could be refactored variously, but we could also "up" from the message content, which might affect how the refactoring could go.
I should say that it does seem to work OK 👍 I've not found a signal emitted within urwid that would solve this for us as it stands. |
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.
20e7ef3
to
fbf73c0
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 Extracting the helper(s) for the footer simplifies things to some degree, but the overlap between tab and right/down is still very similar. I'm currently fairly open to this PR since you have a test. However, the code is highly duplicated and I'd much prefer a solution which combined the two branches if we are able, to avoid that. We can always refactor later, but then we accumulate "technical debt".
13b0a91
to
e32c9d1
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 Thanks for your work. I pulled code locally and it seems to work well! 👍
While the PR is functional, we could simplify the code a bit. I have left a few in-line comments. Let me know if there's anything that needs clarification.
@@ -709,7 +737,8 @@ def test_keypress_CYCLE_COMPOSE_FOCUS(self, write_box, tab_key, | |||
write_box.stream_box_view(stream_id) | |||
else: | |||
write_box.private_box_view() | |||
size = widget_size(write_box) | |||
# FIXME: Use widget_size(), instead of hard-coded 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.
Why aren't we using 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.
Well, I tried using widget_size
, but for some cases, the write-box
changes to box widget instead of flow and returns a (maxcol, maxrow)
size instead of just (maxcol, )
. This made the tests fail for such cases. Let me try to dig more into this and see if I can get a fix for this.
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.
Sorry for the late reply. I got busy with other PR's since finding the root+fix of this particular issue was taking forever. :(
I have tried to dig more on this, but it seems like it's an internal urwid
issue that I am unable to resolve. While looking at this, I realized that the whole write_box
is sometimes recognized as "flow widget" for all tests (that's when all the tests pass), but sometimes the write_box
is determined as "box widget" for all tests (2 tests fail in this case).
I also found that in the latter case, the tests only fail for "DOWN" keypresses, because it can't be handled properly by super()
i.e. urwid's container.py
. I can fix the whole issue by not letting the "DOWN" keypress being handled by urwid and returning early after manually handling, but it seems to have other side-effects and does not look clean.
zulipterminal/ui_tools/boxes.py
Outdated
('code', primary_key_for_command('AUTOCOMPLETE_REVERSE')), | ||
' to autocomplete.' | ||
] | ||
self.view.set_footer_text(footer_message, 3) |
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.
The method is calling an existing method, set_footer_text
, with a particular error message. This could lead us to a state where we have multiple methods that essentially do the same thing with different arguments for different error types.
Another way could be to just have an ERROR_TEMPLATES
data structure that could be used to pass an appropriate error message to the existing set_footer_text
method.
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.
Would it make sense to define the ERROR_TEMPLATES
in a separate module?
This commit refactors code for footer notification in case of invalid recipients (stream/email) in the WriteBox to separate helper function. This prevents duplication of code and allows reusability. This function can now be called with a custom error message that will be displayed in the footer after appending it with a common typeahead suggestion. Tests amended.
This commit disables cycling from the recipient box (Stream/To) using arrow keys if recipient is invalid, similar to Tab. Cycling through the MessageBox now looks for arrow key events and checks for recipient name's validity when losing focus from the recipient box. This should prevent sending of messages to incorrect recipients. Currently, only RIGHT and DOWN keypress is monitored since these are the only keys that can cycle focus from the recipients box to some other box, according to our current MessageBox layout. Tests amended. Fixes zulip#779.
Heads up @zee-bit, 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 |
This PR disables cycling from the recipient box to any other box inside the
WriteBox
view using arrow keys, if the recipient name is invalid. This is very similar toCYCLE_COMPOSE_FOCUS
using Tab key. Tests have also been updated and amended.This PR fixes #779.