mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
fix(app): copy selected message text without markdown (#2759)
This commit is contained in:
1 parent
91a2604e9e
commit
7d56481aba
4 files changed
+38
-13
No files matched your search
+1
-1
@@ -244,7 +244,7 @@ function renderTableRow(
|
||||
export function TableRenderer({node, id, renderChildren, options}: RendererProps<TableNode>): React.ReactElement {
|
||||
const copyText = renderTableNodeToMarkdown(node, {
|
||||
channelId: options.channelId,
|
||||
preserveMarkdown: true,
|
||||
preserveMarkdown: false,
|
||||
includeEmojiNames: true,
|
||||
i18n: options.i18n,
|
||||
});
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
import {MarkdownContext} from '@app/features/messaging/components/markdown/renderers/RendererTypes';
|
||||
import type {Message} from '@app/features/messaging/models/MessagingMessage';
|
||||
import {getParserFlagsForContext} from '@app/features/messaging/utils/markdown/MarkdownParserFlags';
|
||||
import {parseAndRenderToPlaintext} from '@app/features/messaging/utils/markdown/Plaintext';
|
||||
import {
|
||||
type PlaintextRenderOptions,
|
||||
parseAndRenderToPlaintext,
|
||||
renderAstToPlaintext,
|
||||
} from '@app/features/messaging/utils/markdown/Plaintext';
|
||||
import type {Node} from '@app/features/messaging/utils/markdown/parser/Nodes';
|
||||
import * as DateUtils from '@app/features/user/utils/DateFormatting';
|
||||
import {MessageEmbedTypes} from '@fluxer/constants/src/ChannelConstants';
|
||||
import type {MessageEmbed} from '@fluxer/schema/src/domains/message/EmbedSchemas';
|
||||
@@ -102,6 +107,17 @@ function buildOmittedEmbedUrls(content?: string | null, renderedContent?: string
|
||||
return urls;
|
||||
}
|
||||
|
||||
function createPlaintextCopyOptions(context: MarkdownCopyContext): PlaintextRenderOptions {
|
||||
return {
|
||||
channelId: context.channelId,
|
||||
preserveMarkdown: false,
|
||||
includeEmojiNames: true,
|
||||
includeLinkUrls: true,
|
||||
mentionChannels: context.mentionChannels,
|
||||
i18n: context.i18n,
|
||||
};
|
||||
}
|
||||
|
||||
function renderMarkdownCopyText(
|
||||
content: string | undefined | null,
|
||||
parserFlags: number,
|
||||
@@ -110,14 +126,11 @@ function renderMarkdownCopyText(
|
||||
if (!content) {
|
||||
return '';
|
||||
}
|
||||
return parseAndRenderToPlaintext(content, parserFlags, {
|
||||
channelId: context.channelId,
|
||||
preserveMarkdown: false,
|
||||
includeEmojiNames: true,
|
||||
includeLinkUrls: true,
|
||||
mentionChannels: context.mentionChannels,
|
||||
i18n: context.i18n,
|
||||
});
|
||||
return parseAndRenderToPlaintext(content, parserFlags, createPlaintextCopyOptions(context));
|
||||
}
|
||||
|
||||
export function buildMessageContentCopyText(nodes: Array<Node>, context: MarkdownCopyContext): string {
|
||||
return normaliseCopyBlock(renderAstToPlaintext(nodes, createPlaintextCopyOptions(context)));
|
||||
}
|
||||
|
||||
function buildAttachmentCopyText(attachment: MessageAttachment): string {
|
||||
|
||||
@@ -44,7 +44,7 @@ describe('Message selection copy utils', () => {
|
||||
expect(buildMessageSelectionCopyTextForRange({rootElement: root, selectionRange: range})).toBe(tableCopyText);
|
||||
});
|
||||
it('does not duplicate a block message header when a bot badge is selected with the body', () => {
|
||||
const messageContent = '## App Canary Deployed\n\nVersion: `2026.519.3`\nImage: `2026.519.3`';
|
||||
const messageContent = 'App Canary Deployed\n\nVersion: 2026.519.3\nImage: 2026.519.3';
|
||||
document.body.innerHTML = [
|
||||
'<div data-message-selection-root="true">',
|
||||
'<div data-message-id="message-1" data-is-group-start="true">',
|
||||
|
||||
Reference in new issue
Block a user