mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-15 16:59:41 +00:00
[Glitch] fix: Don't submit post when pressing Enter in CW field
Port ee21f72211 to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
@@ -100,7 +100,13 @@ class ComposeForm extends ImmutablePureComponent {
|
|||||||
this.props.onChange(e.target.value);
|
this.props.onChange(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleKeyDown = (e) => {
|
blurOnEscape = (e) => {
|
||||||
|
if (['esc', 'escape'].includes(e.key.toLowerCase())) {
|
||||||
|
e.target.blur();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleKeyDownPost = (e) => {
|
||||||
if (e.key.toLowerCase() === 'enter' && (e.ctrlKey || e.metaKey)) {
|
if (e.key.toLowerCase() === 'enter' && (e.ctrlKey || e.metaKey)) {
|
||||||
this.handleSubmit(e);
|
this.handleSubmit(e);
|
||||||
}
|
}
|
||||||
@@ -109,11 +115,23 @@ class ComposeForm extends ImmutablePureComponent {
|
|||||||
this.handleSecondarySubmit(e);
|
this.handleSecondarySubmit(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (['esc', 'escape'].includes(e.key.toLowerCase())) {
|
this.blurOnEscape(e);
|
||||||
this.textareaRef.current?.blur();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleKeyDownSpoiler = (e) => {
|
||||||
|
if (e.key.toLowerCase() === 'enter') {
|
||||||
|
if (e.ctrlKey || e.metaKey) {
|
||||||
|
this.handleSubmit();
|
||||||
|
} else if (e.altKey) {
|
||||||
|
this.handleSecondarySubmit(e);
|
||||||
|
} else {
|
||||||
|
e.preventDefault();
|
||||||
|
this.textareaRef.current?.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.blurOnEscape(e);
|
||||||
|
}
|
||||||
|
|
||||||
getFulltextForCharacterCounting = () => {
|
getFulltextForCharacterCounting = () => {
|
||||||
return [this.props.spoiler? this.props.spoilerText: '', countableText(this.props.text)].join('');
|
return [this.props.spoiler? this.props.spoilerText: '', countableText(this.props.text)].join('');
|
||||||
};
|
};
|
||||||
@@ -269,7 +287,7 @@ class ComposeForm extends ImmutablePureComponent {
|
|||||||
value={this.props.spoilerText}
|
value={this.props.spoilerText}
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
onChange={this.handleChangeSpoilerText}
|
onChange={this.handleChangeSpoilerText}
|
||||||
onKeyDown={this.handleKeyDown}
|
onKeyDown={this.handleKeyDownSpoiler}
|
||||||
ref={this.setSpoilerText}
|
ref={this.setSpoilerText}
|
||||||
suggestions={this.props.suggestions}
|
suggestions={this.props.suggestions}
|
||||||
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
|
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
|
||||||
@@ -294,7 +312,7 @@ class ComposeForm extends ImmutablePureComponent {
|
|||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
suggestions={this.props.suggestions}
|
suggestions={this.props.suggestions}
|
||||||
onFocus={this.handleFocus}
|
onFocus={this.handleFocus}
|
||||||
onKeyDown={this.handleKeyDown}
|
onKeyDown={this.handleKeyDownPost}
|
||||||
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
|
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
|
||||||
onSuggestionsClearRequested={this.onSuggestionsClearRequested}
|
onSuggestionsClearRequested={this.onSuggestionsClearRequested}
|
||||||
onSuggestionSelected={this.onSuggestionSelected}
|
onSuggestionSelected={this.onSuggestionSelected}
|
||||||
|
|||||||
Reference in New Issue
Block a user