mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
fix(app): wrap pasted links from any source, not just Fluxer's own clipboard (#1752)
This commit is contained in:
1 parent
5aa283e8e0
commit
59887ad404
4 files changed
+54
-35
No files matched your search
@@ -13,6 +13,7 @@ import {
|
||||
parseComposerClipboardSlice,
|
||||
} from '@app/features/lexical/composer/ComposerClipboard';
|
||||
import type {ComposerHandle} from '@app/features/lexical/composer/ComposerHandle';
|
||||
import {resolvePastedLinkInsertion} from '@app/features/lexical/composer/ComposerLinkPaste';
|
||||
import {showAttachmentPermissionDeniedModal} from '@app/features/messaging/components/alerts/AttachmentPermissionDeniedModal';
|
||||
import {FileSizeTooLargeModal} from '@app/features/messaging/components/alerts/FileSizeTooLargeModal';
|
||||
import {TooManyAttachmentsModal} from '@app/features/messaging/components/alerts/TooManyAttachmentsModal';
|
||||
@@ -32,7 +33,7 @@ import {modal} from '@app/features/ui/commands/ModalCommands';
|
||||
import ContextMenuState from '@app/features/ui/state/ContextMenu';
|
||||
import KeyboardMode from '@app/features/ui/state/KeyboardMode';
|
||||
import Users from '@app/features/user/state/Users';
|
||||
import {COMMAND_PRIORITY_HIGH, PASTE_COMMAND} from 'lexical';
|
||||
import {$getSelection, $isRangeSelection, COMMAND_PRIORITY_HIGH, PASTE_COMMAND} from 'lexical';
|
||||
import type React from 'react';
|
||||
import {useCallback, useEffect} from 'react';
|
||||
|
||||
@@ -68,6 +69,19 @@ function createComposerPasteSlice(pastedText: string, segments: ReadonlyArray<Me
|
||||
return {display: displayParts.join(''), segments: projectedSegments};
|
||||
}
|
||||
|
||||
function $insertLinkAroundSelection(pastedText: string): boolean {
|
||||
const selection = $getSelection();
|
||||
if (!$isRangeSelection(selection) || selection.isCollapsed()) {
|
||||
return false;
|
||||
}
|
||||
const replacement = resolvePastedLinkInsertion(pastedText, selection.getTextContent());
|
||||
if (replacement === null) {
|
||||
return false;
|
||||
}
|
||||
selection.insertText(replacement);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function useChannelComposerPaste({
|
||||
channel,
|
||||
handleRef,
|
||||
@@ -230,6 +244,10 @@ export function useChannelComposerPaste({
|
||||
void handlePasteExceedsLimit(pastedText);
|
||||
return true;
|
||||
}
|
||||
if ($insertLinkAroundSelection(pastedText)) {
|
||||
event.preventDefault();
|
||||
return true;
|
||||
}
|
||||
if (!insertPastedText(pastedText)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user