Skip to content

Commit

Permalink
fix(chat): AT feature shouldn't turn on during SourceCodeBrowser (#3752)
Browse files Browse the repository at this point in the history
* fix(chat): add type annotations for suggestion handling and improve conditional rendering

* feat(chat): allow dynamic mention suggestions based on workspace files

* refactor(chat): remove unused Editor import and simplify mention suggestion logic

* fix(chat): enhance mention suggestion logic to consider content match in editor state

* refactor(chat): simplify async function parameters and improve readability in prompt form

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
Sma1lboy and autofix-ci[bot] authored Jan 23, 2025
1 parent d46403d commit 56c25c1
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion 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 { isEqual } from 'lodash-es'
import { EditorFileContext } from 'tabby-chat-panel/index'
import tippy, { GetReferenceClientRect, Instance } from 'tippy.js'
Expand Down Expand Up @@ -89,6 +93,21 @@ function PromptFormRenderer(
deleteTriggerWithBackspace: true,
// Customize how mention suggestions are fetched and rendered
suggestion: {
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 }) => {
if (!listFileInWorkspace) return []
Expand Down Expand Up @@ -255,7 +274,7 @@ function PromptFormRenderer(
</span>
<div
className="max-h-32 flex-1 overflow-y-auto py-4"
onClick={e => {
onClick={() => {
if (editor && !editor.isFocused) {
editor?.commands.focus()
}
Expand Down

0 comments on commit 56c25c1

Please sign in to comment.