@@ -61,7 +61,8 @@ import { invoke } from '@tauri-apps/api/core'
6161import { useToast } from '../plugins/toast'
6262import { StreamLanguage } from '@codemirror/language'
6363import { EditorConfig } from '../types/app.ts'
64- import { EditorView , hoverTooltip } from '@codemirror/view'
64+ import { EditorView } from '@codemirror/view'
65+ import { useCodeMirrorFunctionHelp } from './useCodeMirrorFunctionHelp'
6566
6667interface Props
6768{
@@ -72,6 +73,7 @@ interface Props
7273export function useCodeMirrorEditor ( props : Props )
7374{
7475 const toast = useToast ( )
76+ const { showFunctionHelpHover, functionHelpTheme } = useCodeMirrorFunctionHelp ( )
7577
7678 // 状态管理
7779 const isReady = ref ( false )
@@ -192,32 +194,6 @@ export function useCodeMirrorEditor(props: Props)
192194 }
193195 } )
194196
195- // 显示函数提示扩展
196- const showFunctionHelpHover = hoverTooltip ( ( view , pos , side ) => {
197- let { from, to, text } = view . state . doc . lineAt ( pos )
198- let start = pos , end = pos
199- while ( start > from && / \w / . test ( text [ start - from - 1 ] ) ) {
200- start --
201- }
202- while ( end < to && / \w / . test ( text [ end - from ] ) ) {
203- end ++
204- }
205- if ( start == pos && side < 0 || end == pos && side > 0 ) {
206- return null
207- }
208- return {
209- pos : start ,
210- end,
211- above : true ,
212- create ( _view )
213- {
214- let dom = document . createElement ( 'div' )
215- dom . textContent = text . slice ( start - from , end - from )
216- return { dom }
217- }
218- }
219- } , { hoverTime : 500 } )
220-
221197 // 更新扩展的函数
222198 const updateExtensions = async ( showLineNumbers ?: boolean , showFunctionHelp ?: boolean ) => {
223199 const result = [ ]
@@ -226,6 +202,9 @@ export function useCodeMirrorEditor(props: Props)
226202 const themeExtension = getThemeExtension ( editorConfig . value ?. theme )
227203 result . push ( themeExtension )
228204
205+ // 添加函数帮助主题
206+ result . push ( functionHelpTheme )
207+
229208 // 添加语言扩展
230209 if ( props . language ) {
231210 const langExtension = getLanguageExtension ( props . language )
@@ -255,7 +234,7 @@ export function useCodeMirrorEditor(props: Props)
255234 }
256235 }
257236
258- // 加载编辑器配置
237+ // 其余代码完全保持不变...
259238 const loadEditorConfig = async ( ) => {
260239 try {
261240 const globalConfig = await invoke < any > ( 'get_app_config' )
@@ -363,4 +342,4 @@ export function useCodeMirrorEditor(props: Props)
363342 getThemeExtension,
364343 getLanguageExtension
365344 }
366- }
345+ }
0 commit comments