From db9d93ebee17dedb4b95f08b30ce05986fbe0897 Mon Sep 17 00:00:00 2001 From: VH Date: Tue, 16 May 2023 18:58:43 +0700 Subject: [PATCH 1/3] Consolidate handle keyboard ESCAPE in composer --- src/pages/home/report/ReportActionCompose.js | 30 ++++---------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 062c4cfc5d60..8b7ed58475e5 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -231,24 +231,6 @@ class ReportActionCompose extends React.Component { this.focus(false); }); - const shortcutConfig = CONST.KEYBOARD_SHORTCUTS.ESCAPE; - this.unsubscribeEscapeKey = KeyboardShortcut.subscribe( - shortcutConfig.shortcutKey, - () => { - const suggestionsExist = this.state.suggestedEmojis.length > 0 || this.state.suggestedMentions.length > 0; - - if (!this.state.isFocused || this.comment.length === 0 || suggestionsExist) { - return; - } - - this.updateComment('', true); - }, - shortcutConfig.descriptionKey, - shortcutConfig.modifiers, - true, - true, - ); - this.setMaxLines(); this.updateComment(this.comment); @@ -293,10 +275,6 @@ class ReportActionCompose extends React.Component { componentWillUnmount() { ReportActionComposeFocusManager.clear(); - - if (this.unsubscribeEscapeKey) { - this.unsubscribeEscapeKey(); - } } onSelectionChange(e) { @@ -765,9 +743,13 @@ class ReportActionCompose extends React.Component { } return; } - if (e.key === CONST.KEYBOARD_SHORTCUTS.ESCAPE.shortcutKey && suggestionsExist) { + if (e.key === CONST.KEYBOARD_SHORTCUTS.ESCAPE.shortcutKey) { e.preventDefault(); - this.resetSuggestions(); + if (suggestionsExist) { + this.resetSuggestions(); + } else if (this.comment.length > 0) { + this.updateComment('', true); + } return; } From d1cd0c33fa6b2bd78637b90090d89df4bfe32dcf Mon Sep 17 00:00:00 2001 From: VH Date: Tue, 16 May 2023 19:13:58 +0700 Subject: [PATCH 2/3] Replace hard coded by constant --- src/pages/home/report/ReportActionItemMessageEdit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index 797c95c66165..1718f51bbf33 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -252,7 +252,7 @@ class ReportActionItemMessageEdit extends React.Component { if (e.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey && !e.shiftKey) { e.preventDefault(); this.publishDraft(); - } else if (e.key === 'Escape') { + } else if (e.key === CONST.KEYBOARD_SHORTCUTS.ESCAPE.shortcutKey) { e.preventDefault(); this.deleteDraft(); } From a22cb98f33cef0633a742560bbe3b5ec3e008542 Mon Sep 17 00:00:00 2001 From: VH Date: Tue, 16 May 2023 21:43:04 +0700 Subject: [PATCH 3/3] Fix eslint --- src/pages/home/report/ReportActionCompose.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 8b7ed58475e5..628cb5323565 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -48,7 +48,6 @@ import MentionSuggestions from '../../../components/MentionSuggestions'; import withKeyboardState, {keyboardStatePropTypes} from '../../../components/withKeyboardState'; import ArrowKeyFocusManager from '../../../components/ArrowKeyFocusManager'; import OfflineWithFeedback from '../../../components/OfflineWithFeedback'; -import KeyboardShortcut from '../../../libs/KeyboardShortcut'; import * as ComposerUtils from '../../../libs/ComposerUtils'; import * as ComposerActions from '../../../libs/actions/Composer'; import * as Welcome from '../../../libs/actions/Welcome';