From 5ce5669f17e38173db97419a50b0487fbb2f089d Mon Sep 17 00:00:00 2001 From: Hampus Date: Tue, 18 Aug 2026 14:31:23 +0200 Subject: [PATCH] fix(app): allow the inbox shortcut while the composer is empty (#1714) --- .../components/EditingMessageInput.tsx | 13 +----------- .../LexicalChannelTextareaContent.tsx | 20 +++---------------- .../src/features/input/state/InputKeybind.ts | 2 ++ .../messaging/hooks/useMarkdownKeybinds.ts | 3 ++- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/fluxer_app/src/features/channel/components/EditingMessageInput.tsx b/fluxer_app/src/features/channel/components/EditingMessageInput.tsx index 87d578d5e..eda3c9610 100644 --- a/fluxer_app/src/features/channel/components/EditingMessageInput.tsx +++ b/fluxer_app/src/features/channel/components/EditingMessageInput.tsx @@ -16,9 +16,8 @@ import { EDIT_MESSAGE_DESCRIPTOR, EMOJIS_DESCRIPTOR, } from '@app/features/i18n/utils/CommonMessageDescriptors'; -import Keybind from '@app/features/input/state/InputKeybind'; import {LexicalRichInput, type LexicalRichInputHandle} from '@app/features/lexical/composer/LexicalRichInput'; -import {doesEventMatchShortcut, useMarkdownKeybinds} from '@app/features/messaging/hooks/useMarkdownKeybinds'; +import {useMarkdownKeybinds} from '@app/features/messaging/hooks/useMarkdownKeybinds'; import type {Message} from '@app/features/messaging/models/MessagingMessage'; import MessageEdit from '@app/features/messaging/state/MessageEdit'; import {applyMarkdownSegments} from '@app/features/messaging/utils/MarkdownToSegmentUtils'; @@ -155,16 +154,6 @@ export const EditingMessageInput = observer( if (event.defaultPrevented) { return; } - const composer = composerRef.current; - const selection = composer == null ? null : composer.getSelection(); - const hasSelectionRange = selection != null && selection.start !== selection.end; - const inboxCombo = Keybind.getByAction('chat_toggle_inbox').combo; - if (doesEventMatchShortcut(event, inboxCombo) && !hasSelectionRange && actualContent.trim().length === 0) { - event.preventDefault(); - event.stopPropagation(); - ComponentDispatch.dispatch('INBOX_OPEN'); - return; - } if (event.key === 'Escape' && !event.shiftKey && !event.defaultPrevented && !event.nativeEvent.isComposing) { event.preventDefault(); event.stopPropagation(); diff --git a/fluxer_app/src/features/channel/components/LexicalChannelTextareaContent.tsx b/fluxer_app/src/features/channel/components/LexicalChannelTextareaContent.tsx index 1994e6998..a7e165575 100644 --- a/fluxer_app/src/features/channel/components/LexicalChannelTextareaContent.tsx +++ b/fluxer_app/src/features/channel/components/LexicalChannelTextareaContent.tsx @@ -52,8 +52,7 @@ import type {FlatEmoji} from '@app/features/emoji/types/EmojiTypes'; import {ExpressionPickerSheet} from '@app/features/expressions/components/modals/ExpressionPickerSheet'; import GuildGuilds from '@app/features/guild/state/Guilds'; import {CANCEL_DESCRIPTOR, CONTINUE_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors'; -import Keybind from '@app/features/input/state/InputKeybind'; -import type {ComposerHandle, ComposerSelectionRange} from '@app/features/lexical/composer/ComposerHandle'; +import type {ComposerHandle} from '@app/features/lexical/composer/ComposerHandle'; import {insertComposerEmoji} from '@app/features/lexical/composer/ComposerInsertion'; import {LexicalComposerInput} from '@app/features/lexical/composer/LexicalComposerInput'; import { @@ -69,7 +68,7 @@ import {showAttachmentPermissionDeniedModal} from '@app/features/messaging/compo import {FileSizeTooLargeModal} from '@app/features/messaging/components/alerts/FileSizeTooLargeModal'; import {TooManyAttachmentsModal} from '@app/features/messaging/components/alerts/TooManyAttachmentsModal'; import {useTextareaAttachments} from '@app/features/messaging/hooks/useCloudUpload'; -import {doesEventMatchShortcut, useMarkdownKeybinds} from '@app/features/messaging/hooks/useMarkdownKeybinds'; +import {useMarkdownKeybinds} from '@app/features/messaging/hooks/useMarkdownKeybinds'; import {type SendMessageFunction, useMessageSubmission} from '@app/features/messaging/hooks/useMessageSubmission'; import {useTextareaDraftAndTyping} from '@app/features/messaging/hooks/useTextareaDraftAndTyping'; import {useTextareaEditing} from '@app/features/messaging/hooks/useTextareaEditing'; @@ -848,22 +847,9 @@ export const LexicalChannelTextareaContent = observer( }, [channel.guildId]); const handleEditorKeyDown = useCallback( (event: React.KeyboardEvent) => { - const handle = handleRef.current; - let selection: ComposerSelectionRange | null = null; - if (handle !== null) { - selection = handle.getSelection(); - } - const hasSelectionRange = selection ? selection.start !== selection.end : false; - const inboxCombo = Keybind.getByAction('chat_toggle_inbox').combo; - if (doesEventMatchShortcut(event, inboxCombo) && !hasSelectionRange && value.trim().length === 0) { - event.preventDefault(); - event.stopPropagation(); - ComponentDispatch.dispatch('INBOX_OPEN'); - return; - } handleEscapeKey(event); }, - [handleEscapeKey, value], + [handleEscapeKey], ); const handleSubmit = useCallback(() => { if (!canSubmit) { diff --git a/fluxer_app/src/features/input/state/InputKeybind.ts b/fluxer_app/src/features/input/state/InputKeybind.ts index a37e769e0..761bb4021 100644 --- a/fluxer_app/src/features/input/state/InputKeybind.ts +++ b/fluxer_app/src/features/input/state/InputKeybind.ts @@ -662,6 +662,8 @@ const getDefaultKeybinds = ( action: 'chat_toggle_inbox', label: i18n._(TOGGLE_THE_INBOX_DESCRIPTOR), combo: {key: 'i', ctrlOrMeta: true}, + ignoreWhileTyping: true, + editableFocusBehavior: 'allow_when_empty', section: 'chat', }, { diff --git a/fluxer_app/src/features/messaging/hooks/useMarkdownKeybinds.ts b/fluxer_app/src/features/messaging/hooks/useMarkdownKeybinds.ts index c1b1ca8d8..75c09c9f9 100644 --- a/fluxer_app/src/features/messaging/hooks/useMarkdownKeybinds.ts +++ b/fluxer_app/src/features/messaging/hooks/useMarkdownKeybinds.ts @@ -108,7 +108,8 @@ export const doesEventMatchShortcut = (event: ShortcutKeyEvent, target: Partial< }; const shouldPreserveConflictingAction = (action: KeybindCommand, options: MarkdownKeybindScopeOptions): boolean => { if (!options.preserveEditableFocusActions) return false; - return Keybind.getDefaultByAction(action)?.editableFocusBehavior === 'allow'; + const behavior = Keybind.getDefaultByAction(action)?.editableFocusBehavior; + return behavior === 'allow' || behavior === 'allow_when_empty'; }; const getConflictingKeybindActions = (options: MarkdownKeybindScopeOptions = {}): Set => { const actions = new Set();