Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: allow entering non-default values in multi-select#15935

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
matifali merged 4 commits intocoder:mainfromjoobisb:issue#15488
Dec 27, 2024

Conversation

joobisb
Copy link
Contributor

Closes#15488

cliui.Multiselect currently does not allow users to input custom options if zero choices are provided.

Proposed Solution

cliui.MultiSelect should always allow users to specify another option.

For example, when running coder exp prompt-example multi-select:

PS: I have modified the text a bit from the original issue

? Select some things:  [Use arrows to move, space to select, <right> to all, <left> to none, type to filter]> [x] Code  [ ] Chair  [ ] Whale  [ ] Diamond  [ ] Carrot  ... Other+ Add custom value? Select some things:  [Use arrows to move, space to select, <right> to all, <left> to none, type to filter]? Enter custom value: potato⏎? Select some things:  [Use arrows to move, space to select, <right> to all, <left> to none, type to filter]  [x] Code  [ ] Chair  [ ] Whale  [ ] Diamond  [ ] Carrot  [x] potato>  ... Other+ Add custom value

Attaching a recording for the same

Screen.Recording.2024-12-19.at.4.25.12.PM.mov

phorcys420, aaronlehmann, and matifali reacted with heart emoji
@cdr-botcdr-botbot added the communityPull Requests and issues created by the community. labelDec 19, 2024
@@ -101,6 +101,39 @@ func TestMultiSelect(t *testing.T) {
}()
require.Equal(t,items,<-msgChan)
})

t.Run("MultiSelectWithCustomInput",func(t*testing.T) {
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

couldn't add tests to check the custom input flow, we had this check here and not sure if its safe to remove and add interactive tests, please do let me know if there's a better way to incorporate those tests

ifflag.Lookup("test.v")!=nil {

Copy link
Member

Choose a reason for hiding this comment

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

I think historically we've manually tested this usingprompt-example. I agree that it's not ideal :-(

joobisb reacted with thumbs up emoji
@joobisb
Copy link
ContributorAuthor

Hi@johnstcn ,

could you please have a look at this PR?

I do have a question regarding duplicates, if users enters the same custom value twice should we treat it as a single option ? right now it will create 2 duplicate options, what do you think will be the better way to handle that scenario?

@johnstcn
Copy link
Member

I do have a question regarding duplicates, if users enters the same custom value twice should we treat it as a single option ? right now it will create 2 duplicate options, what do you think will be the better way to handle that scenario?

I think it would make more sense to either de-duplicate or validate that the custom option isn't already present.

joobisb reacted with thumbs up emoji

message string
canceled bool
selected bool
isInputMode bool // New field to track if we're adding a custom option
Copy link
Member

Choose a reason for hiding this comment

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

suggestion:isCustomInputMode for consistency

joobisb reacted with thumbs up emoji
Comment on lines -420 to +435
m.cursor =len(options) - 1
m.cursor =maxIndex
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this logic needs to handle whenEnableCustomInput is false. Currently it lets you go over the last valid option.

joobisb reacted with thumbs up emoji
},
Defaults: []string{"Code"},
Defaults: []string{"Code"},
EnableCustomInput: true,
Copy link
Member

Choose a reason for hiding this comment

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

Can we expose this as a flag so we can easily test both with and without custom input?

joobisb reacted with thumbs up emoji
@joobisb
Copy link
ContributorAuthor

I do have a question regarding duplicates, if users enters the same custom value twice should we treat it as a single option ? right now it will create 2 duplicate options, what do you think will be the better way to handle that scenario?

I think it would make more sense to either de-duplicate or validate that the custom option isn't already present.

@johnstcn@DanielleMaywood

I've addressed the comments and handled duplicates as shown in the recording

  • case insensitive comparison - if it exists, it selects and cursor points to the already existing option
  • if not add a new option
Screen.Recording.2024-12-20.at.11.39.55.AM.mov


// Check for duplicates
for i, opt := range m.options {
if strings.EqualFold(opt.option, m.customInput) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% sure about the case-insensitive matching. On the surface, it seems innocuous enough but I'm not sure if there's going to be a case where someone is going to want to differentiateA froma. Let's keep matching case-sensitive for now.
We can add an option for case-insensitive matching later if someone requests it.

joobisb reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

updated the PR!

@matifalimatifali merged commit638247c intocoder:mainDec 27, 2024
29 checks passed
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsDec 27, 2024
@joobisbjoobisb deleted the issue#15488 branchDecember 27, 2024 20:06
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@DanielleMaywoodDanielleMaywoodDanielleMaywood left review comments

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@joobisbjoobisb

Labels
communityPull Requests and issues created by the community.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

cliui: Allow entering non-default values in MultiSelect
4 participants
@joobisb@johnstcn@DanielleMaywood@matifali

[8]ページ先頭

©2009-2025 Movatter.jp