mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 08:52:12 +00:00
- Debug console: typed expressions are kept per project, and Browse Console History (⌥⌘E / Ctrl+Alt+E) lists them, most recent first, to put one back into the input. - Diff viewer: Diff Settings (⇧⌘D / Ctrl+Shift+D) opens the viewer options (side-by-side / unified, whitespace, highlighting, collapsing, scroll sync) as a popup menu.
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
/**
|
|
* Per-project history of expressions typed into the debugger (breakpoint
|
|
* conditions, Evaluate, the debug console), most recent first, as IDEA keeps them.
|
|
*/
|
|
import { useProject } from "@/platform/project";
|
|
|
|
export type HistoryKind = "condition" | "evaluate" | "console";
|
|
|
|
const PREFIX = "openidea.debugger.history.";
|
|
const MAX = 50;
|
|
|
|
function key(kind: HistoryKind): string | null {
|
|
const root = useProject.getState().project?.root;
|
|
return root ? `${PREFIX}${kind}:${root}` : null;
|
|
}
|
|
|
|
export function readHistory(kind: HistoryKind): string[] {
|
|
const k = key(kind);
|
|
if (!k) return [];
|
|
try {
|
|
const raw = JSON.parse(localStorage.getItem(k) ?? "[]") as unknown;
|
|
return Array.isArray(raw) ? raw.filter((e): e is string => typeof e === "string") : [];
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
export function pushHistory(kind: HistoryKind, expression: string) {
|
|
const e = expression.trim();
|
|
const k = key(kind);
|
|
if (!e || !k) return;
|
|
const next = [e, ...readHistory(kind).filter((h) => h !== e)].slice(0, MAX);
|
|
try {
|
|
localStorage.setItem(k, JSON.stringify(next));
|
|
} catch {
|
|
// Storage unavailable: no history.
|
|
}
|
|
}
|
|
|
|
/** Browse History (⌥⌘E) of the focused debug console input, while one has focus. */
|
|
let browseConsoleHistory: (() => void) | null = null;
|
|
|
|
export function setConsoleHistoryBrowser(fn: (() => void) | null) {
|
|
browseConsoleHistory = fn;
|
|
}
|
|
|
|
export function browseFocusedConsoleHistory(): boolean {
|
|
if (!browseConsoleHistory) return false;
|
|
browseConsoleHistory();
|
|
return true;
|
|
}
|