Attachment Modal: Fix pasting from clipboard always inserted in the end (#1188)
This commit is contained in:
parent
215b3d5603
commit
0b287b0f3d
@ -320,7 +320,7 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
if (selection.rangeCount) {
|
if (selection.rangeCount) {
|
||||||
const selectionRange = selection.getRangeAt(0);
|
const selectionRange = selection.getRangeAt(0);
|
||||||
if (isSelectionInsideInput(selectionRange)) {
|
if (isSelectionInsideInput(selectionRange, inputId)) {
|
||||||
if (IS_EMOJI_SUPPORTED) {
|
if (IS_EMOJI_SUPPORTED) {
|
||||||
// Insertion will trigger `onChange` in MessageInput, so no need to setHtml in state
|
// Insertion will trigger `onChange` in MessageInput, so no need to setHtml in state
|
||||||
document.execCommand('insertText', false, text);
|
document.execCommand('insertText', false, text);
|
||||||
@ -347,7 +347,7 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
if (selection.rangeCount) {
|
if (selection.rangeCount) {
|
||||||
const selectionRange = selection.getRangeAt(0);
|
const selectionRange = selection.getRangeAt(0);
|
||||||
if (isSelectionInsideInput(selectionRange)) {
|
if (isSelectionInsideInput(selectionRange, EDITABLE_INPUT_ID)) {
|
||||||
document.execCommand('delete', false);
|
document.execCommand('delete', false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -149,7 +149,7 @@ const MessageInput: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
const selectedText = selectionRange.toString().trim();
|
const selectedText = selectionRange.toString().trim();
|
||||||
if (
|
if (
|
||||||
shouldSupressTextFormatter
|
shouldSupressTextFormatter
|
||||||
|| !isSelectionInsideInput(selectionRange)
|
|| !isSelectionInsideInput(selectionRange, editableInputId || EDITABLE_INPUT_ID)
|
||||||
|| !selectedText
|
|| !selectedText
|
||||||
|| parseEmojiOnlyString(selectedText)
|
|| parseEmojiOnlyString(selectedText)
|
||||||
|| !selectionRange.START_TO_END
|
|| !selectionRange.START_TO_END
|
||||||
|
|||||||
@ -1,15 +1,13 @@
|
|||||||
import { EDITABLE_INPUT_ID } from '../../../../config';
|
|
||||||
|
|
||||||
const MAX_NESTING_PARENTS = 5;
|
const MAX_NESTING_PARENTS = 5;
|
||||||
|
|
||||||
export function isSelectionInsideInput(selectionRange: Range) {
|
export function isSelectionInsideInput(selectionRange: Range, inputId: string) {
|
||||||
const { commonAncestorContainer } = selectionRange;
|
const { commonAncestorContainer } = selectionRange;
|
||||||
let parentNode: HTMLElement | null = commonAncestorContainer as HTMLElement;
|
let parentNode: HTMLElement | null = commonAncestorContainer as HTMLElement;
|
||||||
let iterations = 1;
|
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;
|
parentNode = parentNode.parentElement;
|
||||||
iterations++;
|
iterations++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Boolean(parentNode && parentNode.id === EDITABLE_INPUT_ID);
|
return Boolean(parentNode && parentNode.id === inputId);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user