|
@@ -5,6 +5,7 @@ import { useRemark } from "react-remark"
|
|
|
import styled from "styled-components"
|
|
import styled from "styled-components"
|
|
|
import { useExtensionState } from "../../context/ExtensionStateContext"
|
|
import { useExtensionState } from "../../context/ExtensionStateContext"
|
|
|
import { vscode } from "../../utils/vscode"
|
|
import { vscode } from "../../utils/vscode"
|
|
|
|
|
+import { highlightFzfMatch } from "../../utils/highlight"
|
|
|
|
|
|
|
|
const OpenAiModelPicker: React.FC = () => {
|
|
const OpenAiModelPicker: React.FC = () => {
|
|
|
const { apiConfiguration, setApiConfiguration, openAiModels, onUpdateApiConfig } = useExtensionState()
|
|
const { apiConfiguration, setApiConfiguration, openAiModels, onUpdateApiConfig } = useExtensionState()
|
|
@@ -70,51 +71,6 @@ const OpenAiModelPicker: React.FC = () => {
|
|
|
}))
|
|
}))
|
|
|
}, [modelIds])
|
|
}, [modelIds])
|
|
|
|
|
|
|
|
- const highlightFzfMatch = (text: string, positions: number[]) => {
|
|
|
|
|
- if (!positions.length) return text
|
|
|
|
|
-
|
|
|
|
|
- const parts: { text: string; highlight: boolean }[] = []
|
|
|
|
|
- let lastIndex = 0
|
|
|
|
|
-
|
|
|
|
|
- // Sort positions to ensure we process them in order
|
|
|
|
|
- positions.sort((a, b) => a - b)
|
|
|
|
|
-
|
|
|
|
|
- positions.forEach((pos) => {
|
|
|
|
|
- // Add non-highlighted text before this position
|
|
|
|
|
- if (pos > lastIndex) {
|
|
|
|
|
- parts.push({
|
|
|
|
|
- text: text.substring(lastIndex, pos),
|
|
|
|
|
- highlight: false
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Add highlighted character
|
|
|
|
|
- parts.push({
|
|
|
|
|
- text: text[pos],
|
|
|
|
|
- highlight: true
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- lastIndex = pos + 1
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // Add any remaining text
|
|
|
|
|
- if (lastIndex < text.length) {
|
|
|
|
|
- parts.push({
|
|
|
|
|
- text: text.substring(lastIndex),
|
|
|
|
|
- highlight: false
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Build final string
|
|
|
|
|
- return parts
|
|
|
|
|
- .map(part =>
|
|
|
|
|
- part.highlight
|
|
|
|
|
- ? `<span class="model-item-highlight">${part.text}</span>`
|
|
|
|
|
- : part.text
|
|
|
|
|
- )
|
|
|
|
|
- .join('')
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
const fzf = useMemo(() => {
|
|
const fzf = useMemo(() => {
|
|
|
return new Fzf(searchableItems, {
|
|
return new Fzf(searchableItems, {
|
|
|
selector: item => item.html
|
|
selector: item => item.html
|
|
@@ -127,7 +83,7 @@ const OpenAiModelPicker: React.FC = () => {
|
|
|
const searchResults = fzf.find(searchTerm)
|
|
const searchResults = fzf.find(searchTerm)
|
|
|
return searchResults.map(result => ({
|
|
return searchResults.map(result => ({
|
|
|
...result.item,
|
|
...result.item,
|
|
|
- html: highlightFzfMatch(result.item.html, Array.from(result.positions))
|
|
|
|
|
|
|
+ html: highlightFzfMatch(result.item.html, Array.from(result.positions), "model-item-highlight")
|
|
|
}))
|
|
}))
|
|
|
}, [searchableItems, searchTerm, fzf])
|
|
}, [searchableItems, searchTerm, fzf])
|
|
|
|
|
|