Add parameters for visible and total items of autocomplete dropdown for @ and #
This commit is contained in:
parent
bc9424877c
commit
29cddbcb57
|
|
@ -671,13 +671,17 @@
|
||||||
|
|
||||||
/* Reference Autocomplete */
|
/* Reference Autocomplete */
|
||||||
.reference-autocomplete {
|
.reference-autocomplete {
|
||||||
|
/* 200px для 5 элементов, возможно, нужно заменить на расчёт с помощью padding и размером шрифта */
|
||||||
|
--item-height: 33px; /* высота одного элемента */
|
||||||
|
--visible-items: 10; /* количество видимых элементов */
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
background: var(--background-primary);
|
background: var(--background-primary);
|
||||||
border: 1px solid var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
max-height: 200px;
|
max-height: calc(var(--item-height) * var(--visible-items));
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
min-width: 250px;
|
min-width: 250px;
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,11 @@ export class AutocompleteManager {
|
||||||
private lastCacheUpdate = 0;
|
private lastCacheUpdate = 0;
|
||||||
private readonly CACHE_TTL = 30000; // 30 секунд
|
private readonly CACHE_TTL = 30000; // 30 секунд
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number} MAX_TOTAL_ITEMS Максимальное количество элементов для поиска и кэширования.
|
||||||
|
*/
|
||||||
|
static MAX_TOTAL_ITEMS = 20;
|
||||||
|
|
||||||
constructor(plugin: LLMAgentPlugin) {
|
constructor(plugin: LLMAgentPlugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.setupFileWatcher();
|
this.setupFileWatcher();
|
||||||
|
|
@ -49,13 +54,13 @@ export class AutocompleteManager {
|
||||||
const allFiles = this.fileCache.get('all') || [];
|
const allFiles = this.fileCache.get('all') || [];
|
||||||
|
|
||||||
if (!query.trim()) {
|
if (!query.trim()) {
|
||||||
return allFiles.slice(0, 10); // Показываем первые 10 файлов
|
return allFiles.slice(0, AutocompleteManager.MAX_TOTAL_ITEMS); // Показываем первые 10 файлов
|
||||||
}
|
}
|
||||||
|
|
||||||
const lowercaseQuery = query.toLowerCase();
|
const lowercaseQuery = query.toLowerCase();
|
||||||
return allFiles
|
return allFiles
|
||||||
.filter((item) => item.name.toLowerCase().includes(lowercaseQuery) || item.path.toLowerCase().includes(lowercaseQuery))
|
.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') || [];
|
const allPrompts = this.promptCache.get('all') || [];
|
||||||
|
|
||||||
if (!query.trim()) {
|
if (!query.trim()) {
|
||||||
return allPrompts.slice(0, 10);
|
return allPrompts.slice(0, AutocompleteManager.MAX_TOTAL_ITEMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
const lowercaseQuery = query.toLowerCase();
|
const lowercaseQuery = query.toLowerCase();
|
||||||
return allPrompts
|
return allPrompts
|
||||||
.filter((item) => item.name.toLowerCase().includes(lowercaseQuery) || item.path.toLowerCase().includes(lowercaseQuery))
|
.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
|
const normalizedExcludedFolders = this.plugin.settings.excludedFolders
|
||||||
.filter(folder => folder.trim() !== '')
|
.filter((folder) => folder.trim() !== '')
|
||||||
.map(folder => folder.endsWith('/') ? folder : folder + '/') // Убедимся, что заканчивается на слэш
|
.map((folder) => (folder.endsWith('/') ? folder : folder + '/')) // Убедимся, что заканчивается на слэш
|
||||||
.map(folder => folder.startsWith('/') ? folder.substring(1) : folder); // Удаляем начальный слэш
|
.map((folder) => (folder.startsWith('/') ? folder.substring(1) : folder)); // Удаляем начальный слэш
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
// Пропускаем файлы из исключенных папок
|
// Пропускаем файлы из исключенных папок
|
||||||
|
|
@ -157,8 +162,7 @@ export class AutocompleteManager {
|
||||||
// Нормализуем путь к папке промптов
|
// Нормализуем путь к папке промптов
|
||||||
const normalizedPromptsPath = promptsFolder.replace(/^\/+|\/+$/g, '');
|
const normalizedPromptsPath = promptsFolder.replace(/^\/+|\/+$/g, '');
|
||||||
|
|
||||||
return file.path.startsWith(normalizedPromptsPath + '/') ||
|
return file.path.startsWith(normalizedPromptsPath + '/') || file.path === normalizedPromptsPath;
|
||||||
file.path === normalizedPromptsPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -227,7 +231,7 @@ export class AutocompleteManager {
|
||||||
const normalizedFolder = folder.toLowerCase();
|
const normalizedFolder = folder.toLowerCase();
|
||||||
// Проверяем, начинается ли путь файла с пути исключенной папки
|
// Проверяем, начинается ли путь файла с пути исключенной папки
|
||||||
// Или если файл находится прямо в корне исключенной папки (н.п. "folder/file.md")
|
// Или если файл находится прямо в корне исключенной папки (н.п. "folder/file.md")
|
||||||
if (filePath.startsWith(normalizedFolder) ) {
|
if (filePath.startsWith(normalizedFolder)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user