-
Notifications
You must be signed in to change notification settings - Fork 93
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
fix: shortcut error in loop #340
Conversation
Thanks for spotting this bug and submitting a PR. From what I understand, the problem is as follows:
The problem occurs on subsequent calls to (3) and (4). I see a few possible solutions:
What do you think? |
Ensures that `Choice.auto_shortcut` is set to `False` whenever `Choice.shortcut_key` is set to a `str` value and vice versa Closes tmbo#340
Ensures that `Choice.auto_shortcut` is set to `False` whenever `Choice.shortcut_key` is set to a `str` value and vice versa. Closes tmbo#340
Ensures that `Choice.auto_shortcut` is set to `False` whenever `Choice.shortcut_key` is set to a `str` value and vice versa. Add tests for fix. Closes tmbo#340
Ensures that `Choice.auto_shortcut` is set to `False` whenever `Choice.shortcut_key` is set to a `str` value and vice versa. Add tests for fix. Closes tmbo#340
Ensures that `Choice.auto_shortcut` is set to `False` whenever `Choice.shortcut_key` is set to a `str` value and vice versa. Add tests for fix. Fixes tmbo#340 Signed-off-by: Ross Williams <ross@ross-williams.net>
Ensures that `Choice.auto_shortcut` is set to `False` whenever `Choice.shortcut_key` is set to a `str` value and vice versa. Add tests for fix. Fixes tmbo#340 Signed-off-by: Ross Williams <ross@ross-williams.net>
What is the problem that this PR addresses?
When we use the
select
method within a loop, and theChoice
parameter sequence is defined outside the loop, shortcut keys in alternating loops are presented in a doubled manner of the actual values.example:
How did you solve it?
The root cause is that, during the initialization of the
InquirerControl.choices
in the_init_choices
process, when aChoice
object is instantiated with anotherChoice
object as a parameter, it directly references and passes the return result. This causes theshortcut_key
parameter state of theChoice
object to be retained in the loop, leading to the aforementioned issue.We can resolve this issue by modifying the
build
method of theChoice
class. When accepting a Choice-type parameter, we can return the result using a shallow copy."Checklist