generated from nhcarrigan/template
feat: batch of fixes and features (#56)
## Summary This PR includes a batch of bug fixes and new features: ### Bug Fixes - **Links in chat history now open in default browser** instead of navigating within the app - Closes #54 - **Allow spaces in tab names** - space key no longer acts like enter when renaming tabs - Closes #52 ### New Features - **`/cd` command** - Change the working directory of an active tab with context preservation - Closes #55 - **`/search` command** - Search and highlight matches within the conversation - Closes #32 ## Test Plan - [ ] Click a link in chat history and verify it opens in the default browser - [ ] Rename a tab and verify spaces can be typed - [ ] Use `/cd <path>` and verify the directory changes while preserving conversation context - [ ] Use `/search <query>` and verify matches are highlighted in yellow - [ ] Use `/search` with no args to clear the search highlighting ✨ This PR was created with help from Hikari~ 🌸 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Reviewed-on: #56 Co-authored-by: Hikari <hikari@nhcarrigan.com> Co-committed-by: Hikari <hikari@nhcarrigan.com>
This commit was merged in pull request #56.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { writable, derived } from "svelte/store";
|
||||
|
||||
interface SearchState {
|
||||
query: string;
|
||||
isActive: boolean;
|
||||
matchCount: number;
|
||||
currentMatchIndex: number;
|
||||
}
|
||||
|
||||
const initialState: SearchState = {
|
||||
query: "",
|
||||
isActive: false,
|
||||
matchCount: 0,
|
||||
currentMatchIndex: 0,
|
||||
};
|
||||
|
||||
const searchStore = writable<SearchState>(initialState);
|
||||
|
||||
export const searchState = {
|
||||
subscribe: searchStore.subscribe,
|
||||
|
||||
setQuery: (query: string) => {
|
||||
searchStore.update((state) => ({
|
||||
...state,
|
||||
query,
|
||||
isActive: query.length > 0,
|
||||
currentMatchIndex: 0,
|
||||
}));
|
||||
},
|
||||
|
||||
setMatchCount: (count: number) => {
|
||||
searchStore.update((state) => ({
|
||||
...state,
|
||||
matchCount: count,
|
||||
}));
|
||||
},
|
||||
|
||||
nextMatch: () => {
|
||||
searchStore.update((state) => ({
|
||||
...state,
|
||||
currentMatchIndex:
|
||||
state.matchCount > 0 ? (state.currentMatchIndex + 1) % state.matchCount : 0,
|
||||
}));
|
||||
},
|
||||
|
||||
previousMatch: () => {
|
||||
searchStore.update((state) => ({
|
||||
...state,
|
||||
currentMatchIndex:
|
||||
state.matchCount > 0
|
||||
? (state.currentMatchIndex - 1 + state.matchCount) % state.matchCount
|
||||
: 0,
|
||||
}));
|
||||
},
|
||||
|
||||
clear: () => {
|
||||
searchStore.set(initialState);
|
||||
},
|
||||
};
|
||||
|
||||
export const isSearchActive = derived(searchStore, ($search) => $search.isActive);
|
||||
|
||||
export const searchQuery = derived(searchStore, ($search) => $search.query);
|
||||
Reference in New Issue
Block a user