feat: hide pin and unpin based on existing pinning configuration (#236)
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { Box, Text } from "ink";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { settingsManager } from "../../settings-manager";
|
||||
import { commands } from "../commands/registry";
|
||||
import { useAutocompleteNavigation } from "../hooks/useAutocompleteNavigation";
|
||||
import { colors } from "./colors";
|
||||
import type { AutocompleteProps, CommandMatch } from "./types/autocomplete";
|
||||
|
||||
// Compute filtered command list (excluding hidden commands)
|
||||
const allCommands: CommandMatch[] = Object.entries(commands)
|
||||
const _allCommands: CommandMatch[] = Object.entries(commands)
|
||||
.filter(([, { hidden }]) => !hidden)
|
||||
.map(([cmd, { desc }]) => ({
|
||||
cmd,
|
||||
@@ -42,9 +43,42 @@ export function SlashCommandAutocomplete({
|
||||
cursorPosition = currentInput.length,
|
||||
onSelect,
|
||||
onActiveChange,
|
||||
agentId,
|
||||
workingDirectory = process.cwd(),
|
||||
}: AutocompleteProps) {
|
||||
const [matches, setMatches] = useState<CommandMatch[]>([]);
|
||||
|
||||
// Check pin status to conditionally show/hide pin/unpin commands
|
||||
const allCommands = useMemo(() => {
|
||||
if (!agentId) return _allCommands;
|
||||
|
||||
try {
|
||||
const globalPinned = settingsManager.getGlobalPinnedAgents();
|
||||
const localPinned =
|
||||
settingsManager.getLocalPinnedAgents(workingDirectory);
|
||||
|
||||
const isPinnedGlobally = globalPinned.includes(agentId);
|
||||
const isPinnedLocally = localPinned.includes(agentId);
|
||||
const isPinnedAnywhere = isPinnedGlobally || isPinnedLocally;
|
||||
const isPinnedBoth = isPinnedGlobally && isPinnedLocally;
|
||||
|
||||
return _allCommands.filter((cmd) => {
|
||||
// Hide /pin if agent is pinned both locally AND globally
|
||||
if (cmd.cmd === "/pin" && isPinnedBoth) {
|
||||
return false;
|
||||
}
|
||||
// Hide /unpin if agent is not pinned anywhere
|
||||
if (cmd.cmd === "/unpin" && !isPinnedAnywhere) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} catch (_error) {
|
||||
// If settings aren't loaded, just show all commands
|
||||
return _allCommands;
|
||||
}
|
||||
}, [agentId, workingDirectory]);
|
||||
|
||||
const { selectedIndex } = useAutocompleteNavigation({
|
||||
matches,
|
||||
onSelect: onSelect ? (item) => onSelect(item.cmd) : undefined,
|
||||
@@ -84,7 +118,7 @@ export function SlashCommandAutocomplete({
|
||||
}
|
||||
|
||||
setMatches(newMatches);
|
||||
}, [currentInput, cursorPosition]);
|
||||
}, [currentInput, cursorPosition, allCommands]);
|
||||
|
||||
// Don't show if input doesn't start with "/"
|
||||
if (!currentInput.startsWith("/")) {
|
||||
|
||||
Reference in New Issue
Block a user