Skip to content

Commit

Permalink
fix(chat): enhance mention suggestion logic to consider content match…
Browse files Browse the repository at this point in the history
… in editor state
  • Loading branch information
Sma1lboy committed Jan 23, 2025
1 parent e55ba91 commit 3e7a221
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ee/tabby-ui/components/chat/prompt-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import React, {
useImperativeHandle
} from 'react'
import Document from '@tiptap/extension-document'
import Mention from '@tiptap/extension-mention'
import Paragraph from '@tiptap/extension-paragraph'
import Placeholder from '@tiptap/extension-placeholder'
import Text from '@tiptap/extension-text'
import {
Editor,
EditorContent,
Extension,
Range,
ReactRenderer,
useEditor
} from '@tiptap/react'

import './prompt-form.css'

import { EditorState } from '@tiptap/pm/state'
import { SuggestionKeyDownProps, SuggestionProps } from '@tiptap/suggestion'
import { isEqual } from 'lodash-es'
import { EditorFileContext } from 'tabby-chat-panel/index'
Expand Down Expand Up @@ -90,8 +94,20 @@ function PromptFormRenderer(
deleteTriggerWithBackspace: true,
// Customize how mention suggestions are fetched and rendered
suggestion: {
allow: _props => {
return !!listFileInWorkspace
allow: ({
state,
range
}: {
editor: Editor
state: EditorState
range: Range
isActive?: boolean
}) => {
const $from = state.doc.resolve(range.from)
const type = state.schema.nodes[Mention.name]
const allow = !!$from.parent.type.contentMatch.matchType(type)

return !!listFileInWorkspace && allow
},
char: '@', // Trigger character for mention
items: async ({ query }: { query: string }) => {
Expand Down

0 comments on commit 3e7a221

Please sign in to comment.