mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-08 07:17:39 +00:00
Extract word detection and suggestion logic into reusable utilities and hooks. Add FloatingOverlay and Autocomplete components for intelligent input assistance. Integrate settings panel and abort button directly into ChatInput component. Simplify SessionHeader by removing settings dialog (now in ChatInput).
21 lines
609 B
TypeScript
21 lines
609 B
TypeScript
import { useMemo } from 'react'
|
|
import { findActiveWord } from '@/utils/findActiveWord'
|
|
|
|
/**
|
|
* Hook that detects the active word at the cursor position
|
|
* Returns the active word string if cursor is on a word starting with one of the prefixes
|
|
*/
|
|
export function useActiveWord(
|
|
text: string,
|
|
selection: { start: number; end: number },
|
|
prefixes: string[] = ['@', '/']
|
|
) {
|
|
return useMemo(() => {
|
|
const w = findActiveWord(text, selection, prefixes)
|
|
if (w) {
|
|
return w.activeWord
|
|
}
|
|
return null
|
|
}, [text, selection.start, selection.end, prefixes])
|
|
}
|