Skip to content

Commit 8e8c06d

Browse files
fix: allow deselecting the only repository in All Sources dropdown
1 parent 7259365 commit 8e8c06d

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ All notable changes to the "promptitude" extension will be documented in this fi
1818
- Fixed issue where prompts that were active before "Activate All" would be in a broken state after "Deactivate All".
1919
- Fixed prompt details view not refreshing when "Deactivate All" is clicked while viewing an active prompt.
2020
- Fixed duplicate repositories persisting in configuration by automatically removing them and updating settings when detected.
21+
- Fixed 'All Sources' dropdown preventing users from deselecting the only repository source by implementing sentinel value pattern to distinguish between "all sources" and "no sources selected" states.
2122

2223
## [1.5.0] - 2025-11-12
2324

src/ui/promptCardsWebview.ts

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,17 @@ export class PromptCardsWebviewProvider implements vscode.WebviewViewProvider {
700700
701701
// Apply source filter (only if specific sources are enabled)
702702
if (enabledSources.size > 0) {
703-
filteredPrompts = filteredPrompts.filter(prompt => {
704-
const sourceKey = prompt.repositoryUrl || 'local';
705-
return enabledSources.has(sourceKey);
706-
});
703+
// Check if the sentinel value is present (meaning no sources selected)
704+
if (enabledSources.has('__none__')) {
705+
// No sources selected - show no prompts
706+
filteredPrompts = [];
707+
} else {
708+
// Specific sources selected
709+
filteredPrompts = filteredPrompts.filter(prompt => {
710+
const sourceKey = prompt.repositoryUrl || 'local';
711+
return enabledSources.has(sourceKey);
712+
});
713+
}
707714
}
708715
709716
renderPrompts(filteredPrompts);
@@ -745,6 +752,9 @@ export class PromptCardsWebviewProvider implements vscode.WebviewViewProvider {
745752
// Build source dropdown items
746753
const sourceItems = [];
747754
755+
// Check if sentinel value is present (no sources selected)
756+
const hasNoneSentinel = enabledSources.has('__none__');
757+
748758
// Add "All Sources" option
749759
sourceItems.push(\`
750760
<div class="source-dropdown-item" onclick="toggleAllSources(event)">
@@ -762,7 +772,7 @@ export class PromptCardsWebviewProvider implements vscode.WebviewViewProvider {
762772
763773
// Add repository sources
764774
Array.from(sources.entries()).forEach(([url, data], index) => {
765-
const isChecked = enabledSources.size === 0 || enabledSources.has(url);
775+
const isChecked = (enabledSources.size === 0 && !hasNoneSentinel) || enabledSources.has(url);
766776
const safeId = 'source-repo-' + index;
767777
sourceItems.push(\`
768778
<div class="source-dropdown-item" onclick="toggleSource('\${escapeHtml(url)}', event)">
@@ -777,7 +787,7 @@ export class PromptCardsWebviewProvider implements vscode.WebviewViewProvider {
777787
778788
// Add local prompts
779789
if (localCount > 0) {
780-
const isChecked = enabledSources.size === 0 || enabledSources.has('local');
790+
const isChecked = (enabledSources.size === 0 && !hasNoneSentinel) || enabledSources.has('local');
781791
sourceItems.push(\`
782792
<div class="source-dropdown-item" onclick="toggleSource('local', event)">
783793
<input type="checkbox" id="source-local" \${isChecked ? 'checked' : ''} onchange="toggleSource('local', event)">
@@ -789,9 +799,9 @@ export class PromptCardsWebviewProvider implements vscode.WebviewViewProvider {
789799
\`);
790800
}
791801
792-
const enabledCount = enabledSources.size === 0 ? sources.size + (localCount > 0 ? 1 : 0) : enabledSources.size;
802+
const enabledCount = enabledSources.size === 0 ? sources.size + (localCount > 0 ? 1 : 0) : (hasNoneSentinel ? 0 : enabledSources.size);
793803
const totalSources = sources.size + (localCount > 0 ? 1 : 0);
794-
const sourceFilterLabel = enabledSources.size === 0 ? 'All Sources' : \`\${enabledCount}/\${totalSources}\`;
804+
const sourceFilterLabel = hasNoneSentinel ? 'None Selected' : (enabledSources.size === 0 ? 'All Sources' : \`\${enabledCount}/\${totalSources}\`);
795805
796806
container.innerHTML = \`
797807
<button class="filter-btn \${currentFilter === 'all' ? 'active' : ''}" onclick="setFilter('all')">
@@ -873,16 +883,34 @@ export class PromptCardsWebviewProvider implements vscode.WebviewViewProvider {
873883
const key = p.repositoryUrl || 'local';
874884
allSources.add(key);
875885
});
876-
allSources.forEach(key => {
877-
if (key !== sourceKey) {
878-
enabledSources.add(key);
879-
}
880-
});
886+
887+
// If there's only one source and it's being toggled off, allow it
888+
if (allSources.size === 1) {
889+
// User wants to deselect the only source - use a sentinel value
890+
// to indicate "no sources selected" (different from "all sources")
891+
enabledSources.add('__none__');
892+
} else {
893+
// Multiple sources - add all except the one being toggled off
894+
allSources.forEach(key => {
895+
if (key !== sourceKey) {
896+
enabledSources.add(key);
897+
}
898+
});
899+
}
881900
} else {
882901
// Some sources are filtered
883902
if (enabledSources.has(sourceKey)) {
903+
// Deselecting a source
884904
enabledSources.delete(sourceKey);
905+
906+
// If we just deselected the last real source, add sentinel
907+
if (enabledSources.size === 0) {
908+
enabledSources.add('__none__');
909+
}
885910
} else {
911+
// Selecting a source
912+
// Remove sentinel if present
913+
enabledSources.delete('__none__');
886914
enabledSources.add(sourceKey);
887915
888916
// Check if all sources are now enabled

0 commit comments

Comments
 (0)