diff --git a/src/components/middle/composer/MessageInput.tsx b/src/components/middle/composer/MessageInput.tsx
index b7c60bb64..b2034335a 100644
--- a/src/components/middle/composer/MessageInput.tsx
+++ b/src/components/middle/composer/MessageInput.tsx
@@ -56,6 +56,19 @@ const TEXT_FORMATTER_SAFE_AREA_PX = 90;
// For some reason Safari inserts `
` after user removes text from input
const SAFARI_BR = '
';
+function clearSelection() {
+ const selection = window.getSelection();
+ if (!selection) {
+ return;
+ }
+
+ if (selection.removeAllRanges) {
+ selection.removeAllRanges();
+ } else if (selection.empty) {
+ selection.empty();
+ }
+}
+
const MessageInput: FC = ({
id,
editableInputId,
@@ -106,6 +119,11 @@ const MessageInput: FC = ({
focusEditableElement(inputRef.current!);
}, []);
+ const handleCloseTextFormatter = useCallback(() => {
+ closeTextFormatter();
+ clearSelection();
+ }, [closeTextFormatter]);
+
function checkSelection() {
// Disable the formatter on iOS devices for now.
if (IS_IOS) {
@@ -326,7 +344,7 @@ const MessageInput: FC = ({
isOpen={isTextFormatterOpen}
anchorPosition={textFormatterAnchorPosition}
selectedRange={selectedRange}
- onClose={closeTextFormatter}
+ onClose={handleCloseTextFormatter}
/>
);