Skip to content

Add numbered shortcuts and filter search to Question select/checkbox#2446

Open
RR5555 wants to merge 19 commits intocopier-org:masterfrom
RR5555:question_filter_shortcut
Open

Add numbered shortcuts and filter search to Question select/checkbox#2446
RR5555 wants to merge 19 commits intocopier-org:masterfrom
RR5555:question_filter_shortcut

Conversation

@RR5555
Copy link
Contributor

@RR5555 RR5555 commented Jan 8, 2026

PR Description

This PR adds the questionary options use_shortcuts & use_filter_search to Copier Question, to allow the usage of numbered shortcuts for select questions, and filter search for select/checkbox questions.

It addresses Issue #2155

It adds two new attributes to the Question class:

  • use_shortcuts: bool
  • use_filter_search: bool

Which are passed down to questionary, thus producing the desired effect.

Note

use_filter_search is not compatible with use_jk_keys questionary option which is activated by default. Thus, when use_filter_search is True for a select/checkbox question, we pass and put use_jk_keys to False.

Choice

Although, it is possible to pass both {use_filter_search: True, use_shortcuts: True} for select questions, I have decided to make use_filter_search have precedence over use_shortcuts to avoid any ambiguity. Thus, if both are True for a select question, only use_filter_search is passed and activated.

Usage

use_shortcuts

copier.yaml

 select:
     type: str
     help: Select one option only
     use_shortcuts: true
     default: first
     choices:
         one: first
         two: second
         three: third

This will display:

1) one
2) two
3) three

And pressing 3 will direct the cursor onto 3) three .

use_filter_search

copier.yaml

checkbox:
    type: str
    help: Select any
    multiselect: true
    use_filter_search: true
    choices:
        one: first
        two: second
        three: third
        four: fourth

Pressing t will make a field appeared at the bottom left with / t... while only showing:

o two
o three

Next, pressing w will change the bottom field to / tw.. while only showing:

o two

Pressing Backspace will delete the searched letter one at a time, allowing for correction or new/additional filter search.

Limitation

The two new attributes are only booleans, they are not str|bool, and not rendered.

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 90.62500% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.16%. Comparing base (ba15e57) to head (db9794e).

Files with missing lines Patch % Lines
copier/_user_data.py 30.76% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2446      +/-   ##
==========================================
- Coverage   97.25%   97.16%   -0.10%     
==========================================
  Files          58       59       +1     
  Lines        6751     6846      +95     
==========================================
+ Hits         6566     6652      +86     
- Misses        185      194       +9     
Flag Coverage Δ
unittests 97.16% <90.62%> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

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

Thanks for contributing these great enhancements of choice questions, @RR5555! 🙏

I have a few inline remarks. And could you please document these settings in the docs?

Per reviewer suggestion/request

Reviewed-by: sisp
Refs: copier-org#2446#discussion_r2678784231
@RR5555 RR5555 force-pushed the question_filter_shortcut branch from f043dd4 to 08371bf Compare January 11, 2026 06:01
…_filter_search` to `use_search_filter`

Per reviewer catch to match `questionary` args as intended

Reviewed-by: sisp
Refs: copier-org#2446#discussion_r2678785014
Per reviewer request

Reviewed-by: sisp
Refs: copier-org#2446#discussion_r2678786515
Per reviewer suggestion/request
Remove development leftovers

Reviewed-by: sisp
Refs: copier-org#2446#discussion_r2678777344 copier-org#2446#discussion_r2678779566
Per reviewer suggestion/request

Reviewed-by: sisp
Refs: copier-org#2446#discussion_r2678780560
…_filter`

Per reviewer suggestion/request

Reviewed-by: sisp
Refs: copier-org#2446#pullrequestreview-3647014001
@RR5555
Copy link
Contributor Author

RR5555 commented Jan 11, 2026

Thank you for reviewing another of my PRs ^^

I had a first go at the documentation of the settings (docs(docs/configuring.md): add docs for use_shortcuts & use_search_filter[f8c695e]).
Please let me know what you think.

RR5555 and others added 2 commits January 12, 2026 19:25
…se_searcg_filter`

Per reviewer suggestion/request

Reviewed-by: sisp
Refs: copier-org#2446#discussion_r2678783429
RR5555 and others added 7 commits March 16, 2026 17:57
…al exclusiveness

Per reviewer request.
Before: `use_search_filter`>`use_shortcuts`
After: ValidationError
Before: `multiselect`>`use_shortcuts`
After: ValidationError

Refs: copier-org#2446#pullrequestreview-3687996014
Per reviewer request.

Refs: copier-org#2446#pullrequestreview-3687996014
…add ValidationError tests

Per reviewer request.

Refs: copier-org#2446#discussion_r2718709082
…se_shortcuts` & `use_search_filter`

Per reviewer request.

Refs: copier-org#2446#pullrequestreview-3687996014
Per reviewer request/suggestion.

Refs: copier-org#2446#pullrequestreview-3687996014
@RR5555
Copy link
Contributor Author

RR5555 commented Mar 17, 2026

Thank you for your previous round of review. Sorry for the delay.
Please let me know if I have missed something, or if other improvements are required.

Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

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

Looks great, thank you! 👍 Just a minor request and a question, then we're ready to merge. 🎉

Comment on lines +438 to +467
if self.use_shortcuts:
if self.multiselect:
raise ValidationError.from_exception_data(
title=f"`{self.var_name}`",
line_errors=[
{
"type": PydanticCustomError(
'"`use_shortcuts` & `multiselect` are mutually exclusive"',
"Use either `use_shortcuts: true` or `multiselect: true`",
),
"input": {"use_shortcuts": True, "multiselect": True},
}
],
)
if self.use_search_filter:
raise ValidationError.from_exception_data(
title=f"`{self.var_name}`",
line_errors=[
{
"type": PydanticCustomError(
'"`use_shortcuts` & `use_search_filter` are mutually exclusive"',
"Use either `use_shortcuts: true` or `use_search_filter: true`",
),
"input": {
"use_shortcuts": True,
"use_search_filter": True,
},
}
],
)
Copy link
Member

Choose a reason for hiding this comment

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

While thinking about this some more, I think it's better to move these checks to a Pydantic model validator method to enforce these invariants at object construction time (and remove this code block from the questionary transformation logic).

Some array: "[str, keeps, this, as, a, str]"
```

- **use_shortcuts**: When set to `true`, allows selecting choice question items via
Copy link
Member

Choose a reason for hiding this comment

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

Should we move this list item down by one position to below multiselect and above use_search_filter to group use_shortcuts and use_search_filter?

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

Labels

None yet