Skip to content
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

Make CMD+Enter work for single-selection pages #9672

Merged
merged 4 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/components/OptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,17 @@ class OptionsSelector extends Component {
this.unsubscribeCTRLEnter = KeyboardShortcut.subscribe(
CTRLEnterConfig.shortcutKey,
() => {
if (this.props.canSelectMultipleOptions) {
this.props.onConfirmSelection();
return;
}

const focusedOption = this.state.allOptions[this.state.focusedIndex];
if (!this.canSelectMultipleOptions && !focusedOption) {
if (!focusedOption) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be above the first check since the code inside that block is also using the focusedOption?

Copy link
Contributor Author

@roryabraham roryabraham Jul 1, 2022

Choose a reason for hiding this comment

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

Moving this up as you've suggested breaks things, because it prevents CMD+Enter from creating a group chat if there are participants selected and the search bar is highlighted. But as it turns out, onConfirmSelection doesn't really need the focusedOption and that's not really it's intended use. I did an audit of all of it's usages:

  • here it's only ever triggered for group chats, and createGroup takes no arguments. So I clarified that and replaced the 1:1 createChat method with a noop.
  • here invite user takes no arguments
  • here finalizeParticipants takes no arguments.
  • here confirm take an argument that's only used by the sendMoney flow. And in the sendMoney flow onConfirmSelection is never called. I looked into splitting confirm into confirmSend and confirmRequest, but it feels out-of-scope and everything seems to be working as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good eye though!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok cool.


this.props.onConfirmSelection(focusedOption);
this.selectRow(focusedOption);
},
CTRLEnterConfig.descriptionKey,
CTRLEnterConfig.modifiers,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NewChatPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class NewChatPage extends Component {
shouldFocusOnSelectRow={this.props.isGroupChat}
shouldShowConfirmButton={this.props.isGroupChat}
confirmButtonText={this.props.translate('newChatPage.createGroup')}
onConfirmSelection={this.props.isGroupChat ? this.createGroup : this.createChat}
onConfirmSelection={this.props.isGroupChat ? this.createGroup : () => {}}
/>
)}
</View>
Expand Down