Add parameters for visible and total items of autocomplete dropdown for @ and #

This commit is contained in:
dimitrievgs 2025-09-27 23:51:05 +03:00
parent bc9424877c
commit 29cddbcb57
2 changed files with 76 additions and 68 deletions

View File

@ -671,13 +671,17 @@
/* Reference Autocomplete */
.reference-autocomplete {
/* 200px для 5 элементов, возможно, нужно заменить на расчёт с помощью padding и размером шрифта */
--item-height: 33px; /* высота одного элемента */
--visible-items: 10; /* количество видимых элементов */
position: absolute;
background: var(--background-primary);
border: 1px solid var(--border-color);
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
z-index: 1000;
max-height: 200px;
max-height: calc(var(--item-height) * var(--visible-items));
overflow-y: auto;
min-width: 250px;
max-width: 400px;

View File

@ -25,6 +25,11 @@ export class AutocompleteManager {
private lastCacheUpdate = 0;
private readonly CACHE_TTL = 30000; // 30 секунд
/**
* @property {number} MAX_TOTAL_ITEMS Максимальное количество элементов для поиска и кэширования.
*/
static MAX_TOTAL_ITEMS = 20;
constructor(plugin: LLMAgentPlugin) {
this.plugin = plugin;
this.setupFileWatcher();
@ -49,13 +54,13 @@ export class AutocompleteManager {
const allFiles = this.fileCache.get('all') || [];
if (!query.trim()) {
return allFiles.slice(0, 10); // Показываем первые 10 файлов
return allFiles.slice(0, AutocompleteManager.MAX_TOTAL_ITEMS); // Показываем первые 10 файлов
}
const lowercaseQuery = query.toLowerCase();
return allFiles
.filter((item) => item.name.toLowerCase().includes(lowercaseQuery) || item.path.toLowerCase().includes(lowercaseQuery))
.slice(0, 10);
.slice(0, AutocompleteManager.MAX_TOTAL_ITEMS);
}
/**
@ -73,13 +78,13 @@ export class AutocompleteManager {
const allPrompts = this.promptCache.get('all') || [];
if (!query.trim()) {
return allPrompts.slice(0, 10);
return allPrompts.slice(0, AutocompleteManager.MAX_TOTAL_ITEMS);
}
const lowercaseQuery = query.toLowerCase();
return allPrompts
.filter((item) => item.name.toLowerCase().includes(lowercaseQuery) || item.path.toLowerCase().includes(lowercaseQuery))
.slice(0, 10);
.slice(0, AutocompleteManager.MAX_TOTAL_ITEMS);
}
/**
@ -114,9 +119,9 @@ export class AutocompleteManager {
// Нормализуем пути исключенных папок
const normalizedExcludedFolders = this.plugin.settings.excludedFolders
.filter(folder => folder.trim() !== '')
.map(folder => folder.endsWith('/') ? folder : folder + '/') // Убедимся, что заканчивается на слэш
.map(folder => folder.startsWith('/') ? folder.substring(1) : folder); // Удаляем начальный слэш
.filter((folder) => folder.trim() !== '')
.map((folder) => (folder.endsWith('/') ? folder : folder + '/')) // Убедимся, что заканчивается на слэш
.map((folder) => (folder.startsWith('/') ? folder.substring(1) : folder)); // Удаляем начальный слэш
for (const file of files) {
// Пропускаем файлы из исключенных папок
@ -157,8 +162,7 @@ export class AutocompleteManager {
// Нормализуем путь к папке промптов
const normalizedPromptsPath = promptsFolder.replace(/^\/+|\/+$/g, '');
return file.path.startsWith(normalizedPromptsPath + '/') ||
file.path === normalizedPromptsPath;
return file.path.startsWith(normalizedPromptsPath + '/') || file.path === normalizedPromptsPath;
}
/**