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

Recalculate maxCmdLength on prop change #20776

Merged
merged 1 commit into from
Nov 4, 2019
Merged
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
20 changes: 13 additions & 7 deletions shared/chat/conversation/input-area/normal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ class Input extends React.Component<InputProps, InputState> {
return
}

if (
prevProps.suggestBotCommands != this.props.suggestBotCommands ||
prevProps.suggestCommands != this.props.suggestCommands
) {
// different commands so we need to recalculate max command length
// + 1 for '/'
this._maxCmdLength =
this.props.suggestCommands
.concat(this.props.suggestBotCommands)
.reduce((max, cmd) => (cmd.name.length > max ? cmd.name.length : max), 0) + 1
}

// Otherwise, inject unsent text. This must come after quote
// handling, so as to handle the 'Reply Privately' case.
if (prevProps.conversationIDKey !== this.props.conversationIDKey) {
Expand All @@ -338,13 +350,6 @@ class Input extends React.Component<InputProps, InputState> {
if (!this.props.isSearching) {
this._inputFocus()
}

// potentially different commands so we need to recalculate max command length
// + 1 for '/'
this._maxCmdLength =
this.props.suggestCommands
.concat(this.props.suggestBotCommands)
.reduce((max, cmd) => (cmd.name.length > max ? cmd.name.length : max), 0) + 1
}
}

Expand All @@ -362,6 +367,7 @@ class Input extends React.Component<InputProps, InputState> {
if (this.props.showCommandMarkdown || this.props.showGiphySearch) {
return {data: [], useSpaces: true}
}

const sel = this._input && this._input.getSelection()
if (sel && this._lastText) {
// a little messy. Check if the message starts with '/' and that the cursor is
Expand Down