Support CMD + Enter to publish post

This commit is contained in:
renahlee 2023-04-19 10:51:33 -07:00
parent 8917cf77a0
commit 31df05825c
3 changed files with 77 additions and 59 deletions

View file

@ -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
}

View file

@ -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,