Composer: Fix duplicated pasting from clipboard (#1854)
This commit is contained in:
parent
e3c2ad5f4d
commit
dab1585014
@ -48,6 +48,7 @@ import {
|
|||||||
selectEditingDraft,
|
selectEditingDraft,
|
||||||
selectRequestedText,
|
selectRequestedText,
|
||||||
selectTheme,
|
selectTheme,
|
||||||
|
selectCurrentMessageList,
|
||||||
} from '../../../global/selectors';
|
} from '../../../global/selectors';
|
||||||
import {
|
import {
|
||||||
getAllowedAttachmentOptions,
|
getAllowedAttachmentOptions,
|
||||||
@ -131,6 +132,7 @@ type StateProps =
|
|||||||
isChatWithBot?: boolean;
|
isChatWithBot?: boolean;
|
||||||
isChatWithSelf?: boolean;
|
isChatWithSelf?: boolean;
|
||||||
isChannel?: boolean;
|
isChannel?: boolean;
|
||||||
|
isForCurrentMessageList: boolean;
|
||||||
isRightColumnShown?: boolean;
|
isRightColumnShown?: boolean;
|
||||||
isSelectModeActive?: boolean;
|
isSelectModeActive?: boolean;
|
||||||
isForwarding?: boolean;
|
isForwarding?: boolean;
|
||||||
@ -201,6 +203,7 @@ const Composer: FC<OwnProps & StateProps> = ({
|
|||||||
messageListType,
|
messageListType,
|
||||||
draft,
|
draft,
|
||||||
chat,
|
chat,
|
||||||
|
isForCurrentMessageList,
|
||||||
connectionState,
|
connectionState,
|
||||||
isChatWithBot,
|
isChatWithBot,
|
||||||
isChatWithSelf,
|
isChatWithSelf,
|
||||||
@ -499,7 +502,7 @@ const Composer: FC<OwnProps & StateProps> = ({
|
|||||||
editingDraft,
|
editingDraft,
|
||||||
);
|
);
|
||||||
useDraft(draft, chatId, threadId, htmlRef, setHtml, editingMessage);
|
useDraft(draft, chatId, threadId, htmlRef, setHtml, editingMessage);
|
||||||
useClipboardPaste(insertTextAndUpdateCursor, setAttachments, editingMessage);
|
useClipboardPaste(isForCurrentMessageList, insertTextAndUpdateCursor, setAttachments, editingMessage);
|
||||||
|
|
||||||
const handleEmbeddedClear = useCallback(() => {
|
const handleEmbeddedClear = useCallback(() => {
|
||||||
if (editingMessage) {
|
if (editingMessage) {
|
||||||
@ -1270,6 +1273,10 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
const sendAsUser = sendAsId ? selectUser(global, sendAsId) : undefined;
|
const sendAsUser = sendAsId ? selectUser(global, sendAsId) : undefined;
|
||||||
const sendAsChat = !sendAsUser && sendAsId ? selectChat(global, sendAsId) : undefined;
|
const sendAsChat = !sendAsUser && sendAsId ? selectChat(global, sendAsId) : undefined;
|
||||||
const requestedText = selectRequestedText(global, chatId);
|
const requestedText = selectRequestedText(global, chatId);
|
||||||
|
const currentMessageList = selectCurrentMessageList(global);
|
||||||
|
const isForCurrentMessageList = chatId === currentMessageList?.chatId
|
||||||
|
&& threadId === currentMessageList?.threadId
|
||||||
|
&& messageListType === currentMessageList?.type;
|
||||||
|
|
||||||
const editingDraft = messageListType === 'scheduled'
|
const editingDraft = messageListType === 'scheduled'
|
||||||
? selectEditingScheduledDraft(global, chatId)
|
? selectEditingScheduledDraft(global, chatId)
|
||||||
@ -1283,6 +1290,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
isChatWithBot,
|
isChatWithBot,
|
||||||
isChatWithSelf,
|
isChatWithSelf,
|
||||||
isPrivateChat,
|
isPrivateChat,
|
||||||
|
isForCurrentMessageList,
|
||||||
canScheduleUntilOnline: selectCanScheduleUntilOnline(global, chatId),
|
canScheduleUntilOnline: selectCanScheduleUntilOnline(global, chatId),
|
||||||
isChannel: chat ? isChatChannel(chat) : undefined,
|
isChannel: chat ? isChatChannel(chat) : undefined,
|
||||||
isRightColumnShown: selectIsRightColumnShown(global),
|
isRightColumnShown: selectIsRightColumnShown(global),
|
||||||
|
|||||||
@ -9,11 +9,16 @@ const CLIPBOARD_ACCEPTED_TYPES = ['image/png', 'image/jpeg', 'image/gif'];
|
|||||||
const MAX_MESSAGE_LENGTH = 4096;
|
const MAX_MESSAGE_LENGTH = 4096;
|
||||||
|
|
||||||
const useClipboardPaste = (
|
const useClipboardPaste = (
|
||||||
|
isActive: boolean,
|
||||||
insertTextAndUpdateCursor: (text: string, inputId?: string) => void,
|
insertTextAndUpdateCursor: (text: string, inputId?: string) => void,
|
||||||
setAttachments: StateHookSetter<ApiAttachment[]>,
|
setAttachments: StateHookSetter<ApiAttachment[]>,
|
||||||
editedMessage: ApiMessage | undefined,
|
editedMessage: ApiMessage | undefined,
|
||||||
) => {
|
) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!isActive) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
async function handlePaste(e: ClipboardEvent) {
|
async function handlePaste(e: ClipboardEvent) {
|
||||||
if (!e.clipboardData) {
|
if (!e.clipboardData) {
|
||||||
return;
|
return;
|
||||||
@ -54,7 +59,7 @@ const useClipboardPaste = (
|
|||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('paste', handlePaste, false);
|
document.removeEventListener('paste', handlePaste, false);
|
||||||
};
|
};
|
||||||
}, [insertTextAndUpdateCursor, editedMessage, setAttachments]);
|
}, [insertTextAndUpdateCursor, editedMessage, setAttachments, isActive]);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useClipboardPaste;
|
export default useClipboardPaste;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user