diff options
| author | Fuwn <[email protected]> | 2026-01-30 07:32:54 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-30 07:32:54 +0000 |
| commit | 5f3eba126201e4d679539aa2517bf6a132f29cd0 (patch) | |
| tree | 961afe2ae1d6ca0f23bdbb30930e37bc88884146 /internal/app/search.go | |
| download | faustus-5f3eba126201e4d679539aa2517bf6a132f29cd0.tar.xz faustus-5f3eba126201e4d679539aa2517bf6a132f29cd0.zip | |
feat: Initial commit
Diffstat (limited to 'internal/app/search.go')
| -rw-r--r-- | internal/app/search.go | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/internal/app/search.go b/internal/app/search.go new file mode 100644 index 0000000..b4d3833 --- /dev/null +++ b/internal/app/search.go @@ -0,0 +1,96 @@ +package app + +import ( + "strings" + + "github.com/Fuwn/faustus/internal/claude" +) + +func (m *Model) jumpToSearchResult() { + if len(m.deepSearchResults) == 0 { + return + } + + result := m.deepSearchResults[m.deepSearchIndex] + setupPreview := func() { + m.invalidatePreviewCache() + + m.showPreview = true + m.previewFocus = true + m.previewSearchQuery = m.deepSearchQuery + + if preview := m.preview(); preview != nil { + m.previewSearchMatches = claude.SearchPreview(preview, m.deepSearchQuery) + m.previewSearchIndex = 0 + + if len(m.previewSearchMatches) > 0 && result.Content != "" { + bestMatch := 0 + + for matchIndex, messageIndex := range m.previewSearchMatches { + if messageIndex < len(preview.Messages) { + if strings.Contains(strings.ToLower(preview.Messages[messageIndex].Content), + strings.ToLower(extractSearchSnippet(result.Content))) { + bestMatch = matchIndex + + break + } + } + } + + m.previewSearchIndex = bestMatch + } + + m.scrollToPreviewMatch() + } + } + + for index, session := range m.filtered { + if session.SessionID == result.Session.SessionID { + m.cursor = index + + m.ensureVisible() + setupPreview() + + return + } + } + + for _, session := range m.sessions { + if session.SessionID == result.Session.SessionID { + if session.InTrash && m.tab != TabTrash { + m.tab = TabTrash + + m.updateFiltered() + } else if !session.InTrash && m.tab != TabSessions { + m.tab = TabSessions + + m.updateFiltered() + } + + for filteredIndex, filteredSession := range m.filtered { + if filteredSession.SessionID == session.SessionID { + m.cursor = filteredIndex + + m.ensureVisible() + setupPreview() + + break + } + } + + break + } + } +} + +func extractSearchSnippet(content string) string { + content = strings.TrimPrefix(content, "… ") + content = strings.TrimSuffix(content, " …") + content = strings.TrimSpace(content) + + if len(content) > 30 { + content = content[:30] + } + + return content +} |