about summary refs log tree commit diff
path: root/src/view/com/composer/text-input
diff options
context:
space:
mode:
authorOllie Hsieh <renahlee@outlook.com>2023-04-19 12:27:43 -0700
committerGitHub <noreply@github.com>2023-04-19 12:27:43 -0700
commit3cc0fb1d671e8b04c21cbcb811d91a8db7a322b1 (patch)
tree327bd4db8727c4e0b115725f30a7c7616e788f41 /src/view/com/composer/text-input
parent8917cf77a0a73e38ad769cea090591c229d5a868 (diff)
parent31df05825ca21df7b0108e200681d6c2ab83fe33 (diff)
downloadvoidsky-3cc0fb1d671e8b04c21cbcb811d91a8db7a322b1.tar.zst
Merge pull request #494 from bluesky-social/ollie/APP-91
[APP-91] Support CMD + Enter to publish post
Diffstat (limited to 'src/view/com/composer/text-input')
-rw-r--r--src/view/com/composer/text-input/TextInput.tsx1
-rw-r--r--src/view/com/composer/text-input/TextInput.web.tsx12
2 files changed, 13 insertions, 0 deletions
diff --git a/src/view/com/composer/text-input/TextInput.tsx b/src/view/com/composer/text-input/TextInput.tsx
index 9c111bd38..10ac52b5d 100644
--- a/src/view/com/composer/text-input/TextInput.tsx
+++ b/src/view/com/composer/text-input/TextInput.tsx
@@ -34,6 +34,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
 }
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,