From 31df05825ca21df7b0108e200681d6c2ab83fe33 Mon Sep 17 00:00:00 2001
From: renahlee <renahlee@outlook.com>
Date: Wed, 19 Apr 2023 10:51:33 -0700
Subject: Support CMD + Enter to publish post

---
 src/view/com/composer/text-input/TextInput.web.tsx | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'src/view/com/composer/text-input/TextInput.web.tsx')

diff --git a/src/view/com/composer/text-input/TextInput.web.tsx b/src/view/com/composer/text-input/TextInput.web.tsx
index e75da1791..f21d4ac1a 100644
--- a/src/view/com/composer/text-input/TextInput.web.tsx
+++ b/src/view/com/composer/text-input/TextInput.web.tsx
@@ -26,6 +26,7 @@ interface TextInputProps {
   autocompleteView: UserAutocompleteModel
   setRichText: (v: RichText) => void
   onPhotoPasted: (uri: string) => void
+  onPressPublish: (richtext: RichText) => Promise<false | undefined>
   onSuggestedLinksChanged: (uris: Set<string>) => void
   onError: (err: string) => void
 }
@@ -39,6 +40,7 @@ export const TextInput = React.forwardRef(
       autocompleteView,
       setRichText,
       onPhotoPasted,
+      onPressPublish,
       onSuggestedLinksChanged,
     }: // onError, TODO
     TextInputProps,
@@ -82,6 +84,16 @@ export const TextInput = React.forwardRef(
 
             getImageFromUri(items, onPhotoPasted)
           },
+          handleKeyDown: (_, event) => {
+            if (event.metaKey && event.code === 'Enter') {
+              // Workaround relying on previous state from `setRichText` to
+              // get the updated text content during editor initialization
+              setRichText((state: RichText) => {
+                onPressPublish(state)
+                return state
+              })
+            }
+          },
         },
         content: richtext.text.toString(),
         autofocus: true,
-- 
cgit 1.4.1

