Skip to content

Commit da32fc7

Browse files
Fixed: Variable syntax highlighting lost after copy-paste from external editor in Agentflow V2 (#5513)
* Fixed: Variable syntax highlighting lost after copy-paste from external editor in Agentflow V2 * Fixed: Variable syntax highlighting lost after copy paste * Rename CustomMention.js to customMention.js * Update ExpandRichInputDialog.jsx * Update RichInput.jsx * Update customMention.js * Update ExpandRichInputDialog.jsx * Update RichInput.jsx * lint fix --------- Co-authored-by: Henry Heng <[email protected]>
1 parent 315e3ae commit da32fc7

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

packages/ui/src/ui-component/dialog/ExpandRichInputDialog.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import { useEditor, EditorContent } from '@tiptap/react'
1616
import Placeholder from '@tiptap/extension-placeholder'
1717
import { mergeAttributes } from '@tiptap/core'
1818
import StarterKit from '@tiptap/starter-kit'
19-
import Mention from '@tiptap/extension-mention'
2019
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
2120
import { common, createLowlight } from 'lowlight'
2221
import { suggestionOptions } from '@/ui-component/input/suggestionOption'
2322
import { getAvailableNodesForVariable } from '@/utils/genericHelper'
23+
import { CustomMention } from '@/utils/customMention'
2424

2525
const lowlight = createLowlight(common)
2626

@@ -78,7 +78,7 @@ const extensions = (availableNodesForVariable, availableState, acceptNodeOutputA
7878
StarterKit.configure({
7979
codeBlock: false
8080
}),
81-
Mention.configure({
81+
CustomMention.configure({
8282
HTMLAttributes: {
8383
class: 'variable'
8484
},

packages/ui/src/ui-component/input/RichInput.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { mergeAttributes } from '@tiptap/core'
77
import StarterKit from '@tiptap/starter-kit'
88
import { styled } from '@mui/material/styles'
99
import { Box } from '@mui/material'
10-
import Mention from '@tiptap/extension-mention'
1110
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
1211
import { common, createLowlight } from 'lowlight'
1312
import { suggestionOptions } from './suggestionOption'
1413
import { getAvailableNodesForVariable } from '@/utils/genericHelper'
14+
import { CustomMention } from '@/utils/customMention'
1515

1616
const lowlight = createLowlight(common)
1717

@@ -20,7 +20,7 @@ const extensions = (availableNodesForVariable, availableState, acceptNodeOutputA
2020
StarterKit.configure({
2121
codeBlock: false
2222
}),
23-
Mention.configure({
23+
CustomMention.configure({
2424
HTMLAttributes: {
2525
class: 'variable'
2626
},
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Mention from '@tiptap/extension-mention'
2+
import { PasteRule } from '@tiptap/core'
3+
4+
export const CustomMention = Mention.extend({
5+
renderText({ node }) {
6+
return `{{${node.attrs.label ?? node.attrs.id}}}`
7+
},
8+
addPasteRules() {
9+
return [
10+
new PasteRule({
11+
find: /\{\{([^{}]+)\}\}/g,
12+
handler: ({ match, chain, range }) => {
13+
const label = match[1].trim()
14+
if (label) {
15+
chain()
16+
.deleteRange(range)
17+
.insertContentAt(range.from, {
18+
type: this.name,
19+
attrs: { id: label, label: label }
20+
})
21+
}
22+
}
23+
})
24+
]
25+
}
26+
})

0 commit comments

Comments
 (0)