Skip to content

Commit aefb444

Browse files
committed
fix(rich-markdown-editor): keep paste literal inside inline code too
The paste handler skipped a fenced code block but not the inline code mark. Now that inline marks gate the parse, pasting `*italic*` inside inline code would render rich instead of staying literal — extend the code-context guard to editor.isActive('code').
1 parent 4bf7547 commit aefb444

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-paste.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ describe('markdown paste', () => {
9494
expect(paste(editor, '[link](https://example.com)')).toBe(false)
9595
})
9696

97+
it('keeps pasted markdown literal inside inline code', () => {
98+
editor = mount()
99+
editor.commands.setContent('a `codehere` b', { contentType: 'markdown' })
100+
editor.commands.setTextSelection(6)
101+
expect(editor.isActive('code')).toBe(true)
102+
expect(paste(editor, '*italic*')).toBe(false)
103+
})
104+
97105
it('rejects the paste entirely in a read-only editor', () => {
98106
editor = mount(false)
99107
expect(paste(editor, '# heading\n\n- one\n- two')).toBe(false)

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-paste.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ function hasAny(hints: ReadonlyArray<RegExp>, text: string): boolean {
3939

4040
/**
4141
* Parses pasted plain text that looks like markdown into rich content, via the strict CommonMark
42-
* parser ({@link parseMarkdownToDoc}, `marked`). Pastes inside a code block are left untouched (code
43-
* is meant to stay literal).
42+
* parser ({@link parseMarkdownToDoc}, `marked`). Pastes inside a code block or inline code are left
43+
* untouched (code is meant to stay literal).
4444
*
4545
* Provenance decides plain-text-vs-HTML: a `text/html` sibling (copied from a browser, Slack, Notion,
4646
* GitHub, or this editor) is the signal the source was rich. Structural markdown is still parsed from
@@ -64,7 +64,7 @@ export const MarkdownPaste = Extension.create({
6464
props: {
6565
handlePaste: (_view, event) => {
6666
if (!editor.isEditable) return false
67-
if (editor.isActive('codeBlock')) return false
67+
if (editor.isActive('codeBlock') || editor.isActive('code')) return false
6868
const text = event.clipboardData?.getData('text/plain')
6969
if (!text) return false
7070
if (!hasAny(STRUCTURAL_MARKDOWN_HINTS, text)) {

0 commit comments

Comments
 (0)