mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
* feat: implement floating quick command with AI-powered inline editing Add a new floating quick command feature that allows users to interact with AI directly from the editor. Key features include: - Quick Ask panel with draggable modal interface - Multiple interaction modes: ask, edit, and edit-direct - Selection highlight and replace guard for safe text operations - Streaming chat session support for real-time AI responses - Context menu integration for quick access - Resizable and draggable UI components # Conflicts: # src/commands/CustomCommandChatModal.tsx # src/styles/tailwind.css * feat: add persistent selection highlight for Chat panel * refactor: extract persistent highlight factory and fix state consistency * fix: improve popup positioning with flip logic and line-start trap fix - Use selection.head instead of selection.to for anchor point - Fix line-start trap: only apply when head is selection end - Add flip logic: show above when not enough space below - Add horizontal visibility check - Single-line selection: center popup horizontally - Multi-line selection: follow head position - Cursor mode: align near cursor instead of centering
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
/**
|
|
* Mode registry for Quick Ask feature.
|
|
* Manages available modes and their configurations.
|
|
*/
|
|
|
|
import type { QuickAskMode, QuickAskModeConfig } from "./types";
|
|
import { QUICK_COMMAND_SYSTEM_PROMPT } from "@/commands/quickCommandPrompts";
|
|
import { askModeConfig, editModeConfig, editDirectModeConfig } from "./modes";
|
|
|
|
/**
|
|
* Registry class for managing Quick Ask modes.
|
|
*/
|
|
class QuickAskModeRegistry {
|
|
private modes = new Map<QuickAskMode, QuickAskModeConfig>();
|
|
|
|
constructor() {
|
|
// Register built-in modes
|
|
this.register(askModeConfig);
|
|
this.register(editModeConfig);
|
|
this.register(editDirectModeConfig);
|
|
}
|
|
|
|
/**
|
|
* Registers a mode configuration.
|
|
*/
|
|
register(config: QuickAskModeConfig): void {
|
|
this.modes.set(config.id, config);
|
|
}
|
|
|
|
/**
|
|
* Gets a mode configuration by ID.
|
|
*/
|
|
get(id: QuickAskMode): QuickAskModeConfig | undefined {
|
|
return this.modes.get(id);
|
|
}
|
|
|
|
/**
|
|
* Gets all registered modes.
|
|
*/
|
|
getAll(): QuickAskModeConfig[] {
|
|
return Array.from(this.modes.values());
|
|
}
|
|
|
|
/**
|
|
* Gets modes available based on selection state.
|
|
*/
|
|
getAvailable(hasSelection: boolean): QuickAskModeConfig[] {
|
|
return this.getAll().filter((mode) => !mode.requiresSelection || hasSelection);
|
|
}
|
|
|
|
/**
|
|
* Gets the system prompt for a mode.
|
|
*/
|
|
getSystemPrompt(id: QuickAskMode): string {
|
|
const mode = this.get(id);
|
|
return mode?.systemPrompt ?? QUICK_COMMAND_SYSTEM_PROMPT;
|
|
}
|
|
}
|
|
|
|
// Create singleton instance
|
|
export const modeRegistry = new QuickAskModeRegistry();
|