This commit is contained in:
Baobhan Sith
2025-04-25 14:39:44 +08:00
parent 5c2a159792
commit 35deba72c4
7 changed files with 286 additions and 52 deletions
@@ -21,6 +21,7 @@ export const useCommandHistoryStore = defineStore('commandHistory', () => {
const isLoading = ref(false);
const error = ref<string | null>(null);
const uiNotificationsStore = useUiNotificationsStore();
const selectedIndex = ref<number>(-1); // NEW: Index of the selected command in the filtered list
// --- Getters ---
@@ -37,6 +38,26 @@ export const useCommandHistoryStore = defineStore('commandHistory', () => {
// --- Actions ---
// NEW: Action to select the next command in the filtered list
const selectNextCommand = () => {
const history = filteredHistory.value;
if (history.length === 0) {
selectedIndex.value = -1;
return;
}
selectedIndex.value = (selectedIndex.value + 1) % history.length;
};
// NEW: Action to select the previous command in the filtered list
const selectPreviousCommand = () => {
const history = filteredHistory.value;
if (history.length === 0) {
selectedIndex.value = -1;
return;
}
selectedIndex.value = (selectedIndex.value - 1 + history.length) % history.length;
};
// 从后端获取历史记录
const fetchHistory = async () => {
isLoading.value = true;
@@ -108,6 +129,12 @@ export const useCommandHistoryStore = defineStore('commandHistory', () => {
// 设置搜索词
const setSearchTerm = (term: string) => {
searchTerm.value = term;
selectedIndex.value = -1; // Reset selection when search term changes
};
// NEW: Action to reset the selection (Moved before return)
const resetSelection = () => {
selectedIndex.value = -1;
};
return {
@@ -116,10 +143,18 @@ export const useCommandHistoryStore = defineStore('commandHistory', () => {
isLoading,
error,
filteredHistory,
selectedIndex, // NEW: Expose selected index
fetchHistory,
addCommand, // 导出 addCommand
deleteCommand,
clearAllHistory,
setSearchTerm,
selectNextCommand, // NEW: Expose action
selectPreviousCommand, // NEW: Expose action
resetSelection, // Ensure resetSelection is exported
};
// REMOVED resetSelection definition from here
// REMOVED duplicate return block
});
@@ -17,6 +17,7 @@ export const useQuickCommandsStore = defineStore('quickCommands', () => {
const isLoading = ref(false);
const error = ref<string | null>(null);
const uiNotificationsStore = useUiNotificationsStore();
const selectedIndex = ref<number>(-1); // NEW: Index of the selected command in the filtered list
// --- Getters ---
@@ -53,6 +54,26 @@ export const useQuickCommandsStore = defineStore('quickCommands', () => {
// --- Actions ---
// NEW: Action to select the next command in the filtered list
const selectNextCommand = () => {
const commands = filteredAndSortedCommands.value;
if (commands.length === 0) {
selectedIndex.value = -1;
return;
}
selectedIndex.value = (selectedIndex.value + 1) % commands.length;
};
// NEW: Action to select the previous command in the filtered list
const selectPreviousCommand = () => {
const commands = filteredAndSortedCommands.value;
if (commands.length === 0) {
selectedIndex.value = -1;
return;
}
selectedIndex.value = (selectedIndex.value - 1 + commands.length) % commands.length;
};
// 从后端获取快捷指令 (带排序)
const fetchQuickCommands = async () => {
isLoading.value = true;
@@ -141,6 +162,7 @@ export const useQuickCommandsStore = defineStore('quickCommands', () => {
// 设置搜索词
const setSearchTerm = (term: string) => {
searchTerm.value = term;
selectedIndex.value = -1; // Reset selection when search term changes
};
// 设置排序方式并重新获取数据
@@ -151,6 +173,13 @@ export const useQuickCommandsStore = defineStore('quickCommands', () => {
}
};
// NEW: Action to reset the selection
const resetSelection = () => {
selectedIndex.value = -1;
};
// Removed duplicate resetSelection definition
return {
quickCommandsList,
searchTerm,
@@ -158,6 +187,7 @@ export const useQuickCommandsStore = defineStore('quickCommands', () => {
isLoading,
error,
filteredAndSortedCommands, // 使用计算属性
selectedIndex, // NEW: Expose selected index
fetchQuickCommands,
addQuickCommand,
updateQuickCommand,
@@ -165,5 +195,8 @@ export const useQuickCommandsStore = defineStore('quickCommands', () => {
incrementUsage,
setSearchTerm,
setSortBy,
selectNextCommand, // NEW: Expose action
selectPreviousCommand, // NEW: Expose action
resetSelection, // Ensure resetSelection is exported
};
});
+21 -2
View File
@@ -42,6 +42,8 @@ interface SettingsState {
sidebarPaneWidths?: string; // NEW: 存储各侧边栏组件宽度的 JSON 字符串
fileManagerRowSizeMultiplier?: string; // NEW: 文件管理器行大小乘数 (e.g., '1.0')
fileManagerColWidths?: string; // NEW: 文件管理器列宽 JSON 字符串 (e.g., '{"name": 300, "size": 100}')
fileManagerColWidths?: string; // NEW: 文件管理器列宽 JSON 字符串 (e.g., '{"name": 300, "size": 100}')
commandInputSyncTarget?: 'quickCommands' | 'commandHistory' | 'none'; // NEW: 命令输入同步目标
// Add other general settings keys here as needed
[key: string]: string | undefined; // Allow other string settings
}
@@ -198,6 +200,11 @@ export const useSettingsStore = defineStore('settings', () => {
// await updateSetting('fileManagerColWidths', finalFmWidthsString);
// }
// NEW: Command Input Sync Target default
if (settings.value.commandInputSyncTarget === undefined) {
settings.value.commandInputSyncTarget = 'none'; // 默认不同步
}
// --- 语言设置 ---
const langFromSettings = settings.value.language;
console.log(`[SettingsStore] Language from fetched settings: ${langFromSettings}`); // <-- 添加日志
@@ -251,7 +258,8 @@ export const useSettingsStore = defineStore('settings', () => {
'workspaceSidebarPersistent', // +++ 添加侧边栏固定键 +++
'sidebarPaneWidths', // +++ 添加侧边栏宽度对象键 +++
'fileManagerRowSizeMultiplier', // +++ 添加文件管理器行大小键 +++
'fileManagerColWidths' // +++ 添加文件管理器列宽键 +++
'fileManagerColWidths', // +++ 添加文件管理器列宽键 +++
'commandInputSyncTarget' // +++ 添加命令输入同步目标键 +++
];
if (!allowedKeys.includes(key)) {
console.error(`[SettingsStore] 尝试更新不允许的设置键: ${key}`);
@@ -289,7 +297,8 @@ export const useSettingsStore = defineStore('settings', () => {
'workspaceSidebarPersistent', // +++ 添加侧边栏固定键 +++
'sidebarPaneWidths', // +++ 添加侧边栏宽度对象键 +++
'fileManagerRowSizeMultiplier', // +++ 添加文件管理器行大小键 +++
'fileManagerColWidths' // +++ 添加文件管理器列宽键 +++
'fileManagerColWidths', // +++ 添加文件管理器列宽键 +++
'commandInputSyncTarget' // +++ 添加命令输入同步目标键 +++
];
const filteredUpdates: Partial<SettingsState> = {};
let languageUpdate: 'en' | 'zh' | undefined = undefined;
@@ -491,6 +500,15 @@ export const useSettingsStore = defineStore('settings', () => {
return parsedFileManagerColWidths.value;
});
// NEW: Getter for command input sync target
const commandInputSyncTarget = computed(() => {
const target = settings.value.commandInputSyncTarget;
if (target === 'quickCommands' || target === 'commandHistory') {
return target;
}
return 'none'; // Default to 'none' if invalid or not set
});
// --- CAPTCHA Getters (Public Only) ---
const isCaptchaEnabled = computed(() => captchaSettings.value?.enabled ?? false);
const captchaProvider = computed(() => captchaSettings.value?.provider ?? 'none');
@@ -527,5 +545,6 @@ export const useSettingsStore = defineStore('settings', () => {
updateMultipleSettings,
updateSidebarPaneWidth, // +++ 暴露更新特定面板宽度的 action +++
updateFileManagerLayoutSettings, // +++ 暴露更新文件管理器布局的 action +++
commandInputSyncTarget, // +++ 暴露命令输入同步目标 getter +++
};
});