feat(debugger): Browse the debug console history and open diff settings from the keyboard (#162)

- 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.
This commit is contained in:
l0ng-ai
2026-10-29 02:16:37 +08:00
committed by GitHub
parent a28600c55a
commit aeb190ffda
10 changed files with 142 additions and 10 deletions
+26 -2
View File
@@ -39,6 +39,7 @@ import {
type DebugSession,
} from "../state";
import { VariablesView, type VarRoot } from "./VariablesView";
import { pushHistory, readHistory, setConsoleHistoryBrowser } from "./expressionHistory";
import styles from "./DebugToolWindow.module.css";
import { tx } from "@/platform/i18n";
@@ -542,8 +543,9 @@ function ConsoleView({ session }: { session: DebugSession }) {
const scroller = useRef<HTMLDivElement>(null);
const stick = useRef(true);
const [input, setInput] = useState("");
const history = useRef<string[]>([]);
const history = useRef<string[]>(readHistory("console"));
const historyPos = useRef(-1);
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
const el = scroller.current;
@@ -553,7 +555,8 @@ function ConsoleView({ session }: { session: DebugSession }) {
const submit = async () => {
const e = input.trim();
if (!e) return;
history.current = [e, ...history.current.filter((h) => h !== e)].slice(0, 100);
pushHistory("console", e);
history.current = readHistory("console");
historyPos.current = -1;
setInput("");
appendConsole(session.id, "input", `> ${e}\n`);
@@ -565,6 +568,24 @@ function ConsoleView({ session }: { session: DebugSession }) {
}
};
/** IDEA's Browse History popup: the expressions typed before, most recent first. */
const browseHistory = () => {
const el = inputRef.current;
const r = el?.getBoundingClientRect();
const items: MenuItem[] = history.current.length
? history.current.slice(0, 30).map((h, i) => ({
id: String(i),
label: h.length > 120 ? `${h.slice(0, 120)}…` : h,
run: () => {
setInput(h);
historyPos.current = i;
el?.focus();
},
}))
: [{ id: "none", label: "No history", disabled: true }];
showContextMenu({ x: r?.left ?? 120, y: (r?.top ?? 200) - 4 }, items);
};
const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
e.preventDefault();
@@ -607,7 +628,10 @@ function ConsoleView({ session }: { session: DebugSession }) {
›
</span>
<input
ref={inputRef}
className={styles.evalInput}
onFocus={() => setConsoleHistoryBrowser(browseHistory)}
onBlur={() => setConsoleHistoryBrowser(null)}
value={input}
onChange={(e) => setInput(e.target.value)}
onKeyDown={onKeyDown}