From 26ba2db53f68eb6ab0ef5ae37a8ea4a8506282bb Mon Sep 17 00:00:00 2001 From: diondiondion Date: Mon, 21 Jul 2025 17:57:20 +0200 Subject: [PATCH] [Glitch] fix: Don't submit post when pressing Enter in CW field Port ee21f7221143d94aac00a6cbadea352ebfe44905 to glitch-soc Signed-off-by: Claire --- .../compose/components/compose_form.jsx | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx index bb366f6066..e29f6b218d 100644 --- a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx +++ b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx @@ -100,7 +100,13 @@ class ComposeForm extends ImmutablePureComponent { 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)) { this.handleSubmit(e); } @@ -109,11 +115,23 @@ class ComposeForm extends ImmutablePureComponent { this.handleSecondarySubmit(e); } - if (['esc', 'escape'].includes(e.key.toLowerCase())) { - this.textareaRef.current?.blur(); - } + this.blurOnEscape(e); }; + 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 = () => { return [this.props.spoiler? this.props.spoilerText: '', countableText(this.props.text)].join(''); }; @@ -269,7 +287,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} @@ -294,7 +312,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}