diff --git a/src/components/middle/composer/Composer.tsx b/src/components/middle/composer/Composer.tsx index d829fbea0..cb08a04c0 100644 --- a/src/components/middle/composer/Composer.tsx +++ b/src/components/middle/composer/Composer.tsx @@ -320,7 +320,7 @@ const Composer: FC = ({ if (selection.rangeCount) { const selectionRange = selection.getRangeAt(0); - if (isSelectionInsideInput(selectionRange)) { + if (isSelectionInsideInput(selectionRange, inputId)) { if (IS_EMOJI_SUPPORTED) { // Insertion will trigger `onChange` in MessageInput, so no need to setHtml in state document.execCommand('insertText', false, text); @@ -347,7 +347,7 @@ const Composer: FC = ({ if (selection.rangeCount) { const selectionRange = selection.getRangeAt(0); - if (isSelectionInsideInput(selectionRange)) { + if (isSelectionInsideInput(selectionRange, EDITABLE_INPUT_ID)) { document.execCommand('delete', false); return; } diff --git a/src/components/middle/composer/MessageInput.tsx b/src/components/middle/composer/MessageInput.tsx index 619067323..77e7b4e5e 100644 --- a/src/components/middle/composer/MessageInput.tsx +++ b/src/components/middle/composer/MessageInput.tsx @@ -149,7 +149,7 @@ const MessageInput: FC = ({ const selectedText = selectionRange.toString().trim(); if ( shouldSupressTextFormatter - || !isSelectionInsideInput(selectionRange) + || !isSelectionInsideInput(selectionRange, editableInputId || EDITABLE_INPUT_ID) || !selectedText || parseEmojiOnlyString(selectedText) || !selectionRange.START_TO_END diff --git a/src/components/middle/composer/helpers/selection.ts b/src/components/middle/composer/helpers/selection.ts index 6eca80f64..bb7e5eb16 100644 --- a/src/components/middle/composer/helpers/selection.ts +++ b/src/components/middle/composer/helpers/selection.ts @@ -1,15 +1,13 @@ -import { EDITABLE_INPUT_ID } from '../../../../config'; - const MAX_NESTING_PARENTS = 5; -export function isSelectionInsideInput(selectionRange: Range) { +export function isSelectionInsideInput(selectionRange: Range, inputId: string) { const { commonAncestorContainer } = selectionRange; let parentNode: HTMLElement | null = commonAncestorContainer as HTMLElement; let iterations = 1; - while (parentNode && parentNode.id !== EDITABLE_INPUT_ID && iterations < MAX_NESTING_PARENTS) { + while (parentNode && parentNode.id !== inputId && iterations < MAX_NESTING_PARENTS) { parentNode = parentNode.parentElement; iterations++; } - return Boolean(parentNode && parentNode.id === EDITABLE_INPUT_ID); + return Boolean(parentNode && parentNode.id === inputId); }