fix: Don't submit post when pressing Enter in CW field (#35445)

This commit is contained in:
diondiondion 2025-07-21 17:57:20 +02:00 committed by GitHub
parent 4de5cbd6f5
commit ee21f72211
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -92,13 +92,29 @@ class ComposeForm extends ImmutablePureComponent {
this.props.onChange(e.target.value);
};
handleKeyDown = (e) => {
if (e.key.toLowerCase() === 'enter' && (e.ctrlKey || e.metaKey)) {
this.handleSubmit();
}
blurOnEscape = (e) => {
if (['esc', 'escape'].includes(e.key.toLowerCase())) {
this.textareaRef.current?.blur();
e.target.blur();
}
}
handleKeyDownPost = (e) => {
if (e.key.toLowerCase() === 'enter' && (e.ctrlKey || e.metaKey)) {
this.handleSubmit();
}
this.blurOnEscape(e);
};
handleKeyDownSpoiler = (e) => {
if (e.key.toLowerCase() === 'enter') {
if (e.ctrlKey || e.metaKey) {
this.handleSubmit();
} else {
e.preventDefault();
this.textareaRef.current?.focus();
}
}
this.blurOnEscape(e);
};
getFulltextForCharacterCounting = () => {
@ -251,7 +267,7 @@ class ComposeForm extends ImmutablePureComponent {
value={this.props.spoilerText}
disabled={isSubmitting}
onChange={this.handleChangeSpoilerText}
onKeyDown={this.handleKeyDown}
onKeyDown={this.handleKeyDownSpoiler}
ref={this.setSpoilerText}
suggestions={this.props.suggestions}
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
@ -276,7 +292,7 @@ class ComposeForm extends ImmutablePureComponent {
onChange={this.handleChange}
suggestions={this.props.suggestions}
onFocus={this.handleFocus}
onKeyDown={this.handleKeyDown}
onKeyDown={this.handleKeyDownPost}
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
onSuggestionsClearRequested={this.onSuggestionsClearRequested}
onSuggestionSelected={this.onSuggestionSelected}