diff --git a/.jules/palette.md b/.jules/palette.md new file mode 100644 index 00000000..25949d31 --- /dev/null +++ b/.jules/palette.md @@ -0,0 +1,3 @@ +## 2024-05-18 - Added "Clear Search" Action to Empty State +**Learning:** When users encounter an empty search state, providing an actionable recovery path directly in the list (like a "Clear Search" command) significantly reduces friction compared to requiring manual deletion. Additionally, programmatically clearing a `QuickPick.value` in VS Code does not trigger `onDidChangeValue`, so the associated search/refresh logic must be called manually to reset the UI state. +**Action:** Always include an actionable "Clear" or "Reset" option directly within empty state UI elements, and remember to manually trigger update handlers when programmatically modifying VS Code `QuickPick` input values. \ No newline at end of file diff --git a/vscode-extension/src/search-provider.ts b/vscode-extension/src/search-provider.ts index 577b3faa..e832420c 100644 --- a/vscode-extension/src/search-provider.ts +++ b/vscode-extension/src/search-provider.ts @@ -76,6 +76,7 @@ export class SearchProvider { private readonly CMD_REBUILD_INDEX = 'command:rebuild-index'; private readonly CMD_CLEAR_CACHE = 'command:clear-cache'; private readonly CMD_SETTINGS = 'command:open-settings'; + private readonly CMD_CLEAR_SEARCH = 'command:clear-search'; private readonly ID_EMPTY_STATE = 'empty-state'; private static readonly CANCEL_BUTTON: vscode.QuickInputButton = { @@ -1528,6 +1529,18 @@ export class SearchProvider { selected: SearchResultItem, quickPick: vscode.QuickPick, ): Promise { + if (selected.result.item.id === this.CMD_CLEAR_SEARCH) { + quickPick.value = ''; + // Manually trigger query change to show history again since onDidChangeValue won't fire programmatically + this.handleQueryChange( + quickPick, + '', + () => {}, + () => {}, + ); + return true; + } + if (selected.result.item.id === this.CMD_NATIVE_SEARCH) { await vscode.commands.executeCommand('workbench.action.findInFiles', { query: quickPick.value, @@ -1654,7 +1667,17 @@ export class SearchProvider { }); }; - // 3. Native Search Action + // 3. Clear Search Action (if query is not empty) + if (query.trim().length > 0) { + addCommandItem( + 'Clear Search', + 'Clear current query and start over', + new vscode.ThemeIcon('clear-all'), + this.CMD_CLEAR_SEARCH, + ); + } + + // 4. Native Search Action addCommandItem( 'Search in Files (Native)', "Use VS Code's native search",