Merge branch 'worktree-agent-ac19ea2d9f670cb36' into claude/practical-noether-1hb2s1
This commit is contained in:
22 files changed
+643
-30
No files matched your search
@@ -3,6 +3,7 @@ import { setLanguage } from "../i18n";
|
||||
import {
|
||||
comboFromEvent,
|
||||
comboMatches,
|
||||
fileShortcutFor,
|
||||
findConflict,
|
||||
formatCombo,
|
||||
isReservedCombo,
|
||||
@@ -201,3 +202,21 @@ describe("[252] tabKeyAction", () => {
|
||||
expect(tabKeyAction(ev({ key: "a", ctrlKey: true }))).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("[170] Datei-Kürzel ausserhalb von Tauri (Browser/Electron-Linux)", () => {
|
||||
it("Strg/Cmd+S speichert, +Umschalt speichert unter, Strg/Cmd+O öffnet", () => {
|
||||
expect(fileShortcutFor(key("s", { ctrlKey: true }))).toBe("save");
|
||||
expect(fileShortcutFor(key("s", { metaKey: true }))).toBe("save");
|
||||
expect(fileShortcutFor(key("S", { ctrlKey: true, shiftKey: true }))).toBe("saveAs");
|
||||
expect(fileShortcutFor(key("o", { ctrlKey: true }))).toBe("open");
|
||||
});
|
||||
it("ohne Strg/Cmd oder mit Alt: nichts (s = Spiegeln bleibt frei)", () => {
|
||||
expect(fileShortcutFor(key("s"))).toBeNull();
|
||||
expect(fileShortcutFor(key("s", { ctrlKey: true, altKey: true }))).toBeNull();
|
||||
expect(fileShortcutFor(key("o", { ctrlKey: true, shiftKey: true }))).toBeNull();
|
||||
});
|
||||
it("kollidiert mit keinem belegbaren Kürzel", () => {
|
||||
const combos = SHORTCUT_DEFS.map((d) => d.defaultCombo);
|
||||
for (const c of ["mod+s", "mod+shift+s", "mod+o"]) expect(combos).not.toContain(c);
|
||||
});
|
||||
});
|
||||
@@ -323,6 +323,21 @@ export function comboMatches(e: KeyboardEvent, combo: string): boolean {
|
||||
return k === key;
|
||||
}
|
||||
|
||||
/** [170] Datei-Kürzel ausserhalb von Tauri. */
|
||||
export type FileShortcut = "save" | "saveAs" | "open";
|
||||
|
||||
/**
|
||||
* [170] Strg/Cmd+S, Strg/Cmd+Umschalt+S, Strg/Cmd+O im Browser und in der Linux-App (Electron, ohne native Menüleiste).
|
||||
* Unter Tauri liefert das native Menü dieselben Kürzel (`native/appMenu.ts`, Accelerator) — dort nicht verwenden.
|
||||
* Fest wie die Menü-Accelerators, nicht umbelegbar (nicht in {@link SHORTCUT_DEFS}).
|
||||
*/
|
||||
export function fileShortcutFor(e: KeyboardEvent): FileShortcut | null {
|
||||
if (comboMatches(e, "mod+shift+s")) return "saveAs";
|
||||
if (comboMatches(e, "mod+s")) return "save";
|
||||
if (comboMatches(e, "mod+o")) return "open";
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Kurzform: matcht `e` gegen die (übersteuerte oder Default-)Kombination von `id`. */
|
||||
export function matchesShortcut(
|
||||
e: KeyboardEvent,
|
||||
|
||||
@@ -32,7 +32,8 @@ import {
|
||||
} from "../editors/elementClipboard";
|
||||
import type { ElementClipboard, ElementSelectionIds, PastedIds } from "../editors/elementClipboard";
|
||||
import { parseClipboardText, serializeClipboardText } from "../editors/elementClipboardSerialize";
|
||||
import { matchesShortcut, tabKeyAction, type ShortcutId, type ShortcutOverrides } from "./keyboardShortcuts";
|
||||
import { fileShortcutFor, matchesShortcut, tabKeyAction, type FileShortcut, type ShortcutId, type ShortcutOverrides } from "./keyboardShortcuts";
|
||||
import { isTauriRuntime } from "../native/projectFile";
|
||||
import { isolateSelectionLayerCodes, showAllLayerCodes } from "./layerIsolate";
|
||||
import { isInModalDialog } from "./modalScope";
|
||||
import { toggleTraceAction } from "./traceActions";
|
||||
@@ -751,3 +752,23 @@ export function useFitShortcuts(fitAll: () => void, fitSelection: () => void, ov
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [overrides]);
|
||||
}
|
||||
|
||||
/**
|
||||
* [170] Strg/Cmd+S (Speichern), +Umschalt (Speichern unter), Strg/Cmd+O (Öffnen) im Browser und in der Linux-App (Electron hat
|
||||
* keine native Menüleiste). Unter Tauri übernimmt das native Menü (Accelerator) — dort nichts tun. Nicht in modalen Dialogen.
|
||||
*/
|
||||
export function useFileShortcuts(handlers: Record<FileShortcut, () => void>): void {
|
||||
const ref = useRef(handlers);
|
||||
ref.current = handlers;
|
||||
useEffect(() => {
|
||||
if (isTauriRuntime()) return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
const action = fileShortcutFor(e);
|
||||
if (!action || isInModalDialog(e.target)) return;
|
||||
e.preventDefault();
|
||||
ref.current[action]();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, []);
|
||||
}
|
||||
@@ -119,6 +119,12 @@ export function useProjectFileActions(
|
||||
activeCategoryCode: string,
|
||||
setActiveLevelId: (id: string) => void,
|
||||
planViewRef: RefObject<PlanViewHandle | null>,
|
||||
/**
|
||||
* [170] Electron: eine per Argument/Doppelklick übergebene Datei ist angekommen. Der Aufrufer wechselt in den Editor
|
||||
* (sonst bliebe der Startbildschirm davor) und meldet, ob die App noch im Startablauf war — dann gibt es nichts zu
|
||||
* verwerfen und die Rückfrage „Ungespeicherte Änderungen" entfällt.
|
||||
*/
|
||||
onLaunchFile?: () => { wasBooting: boolean },
|
||||
) {
|
||||
// Verstecktes Datei-Input zum Laden eines Projekts (Datei-Burger „Öffnen").
|
||||
// Wird NUR im Browser-Pfad benutzt (ohne Tauri) — unter Tauri geht „Öffnen"
|
||||
@@ -760,7 +766,7 @@ export function useProjectFileActions(
|
||||
}
|
||||
};
|
||||
|
||||
const onProjectFileChosen = (file: File, knownPath?: string | null) => {
|
||||
const onProjectFileChosen = (file: File, knownPath?: string | null, askDiscard = true) => {
|
||||
const r = new FileReader();
|
||||
r.onload = () => {
|
||||
const content = String(r.result ?? "");
|
||||
@@ -768,14 +774,16 @@ export function useProjectFileActions(
|
||||
const path = knownPath ?? electronFiles()?.pathForFile(file) ?? null;
|
||||
// Browser-Pfad hat keinen echten Dateipfad → kein Lock für die neue
|
||||
// Datei, aber ein evtl. vorher (unter Tauri) gehaltener Lock wird frei.
|
||||
guardDiscard(() => {
|
||||
const apply = () => {
|
||||
const loaded = openOrOfferBackup(content, path, false);
|
||||
if (!loaded) return;
|
||||
releaseCurrentProjectLock();
|
||||
lastSavedProjectRef.current = loaded;
|
||||
if (path) savePathRef.current = path;
|
||||
setAnonymityProjectFileName(path ?? file.name); // [208] Browser/Electron-Start: kein Pfad, aber der Dateiname
|
||||
});
|
||||
};
|
||||
if (askDiscard) guardDiscard(apply);
|
||||
else apply();
|
||||
};
|
||||
r.onerror = () => notify(`${t("project.open.failed")} ${r.error?.message ?? ""}`, "error");
|
||||
r.readAsText(file);
|
||||
@@ -783,12 +791,19 @@ export function useProjectFileActions(
|
||||
|
||||
// [170] Electron: per Kommandozeile/Doppelklick übergebene .obp (beim Start und von einer zweiten
|
||||
// Instanz) wie eine im Browser gewählte Datei öffnen. Der Ref hält die jeweils aktuelle Fassung.
|
||||
// Kommt die Datei noch im Startablauf (Splash/Startbildschirm), wechselt `onLaunchFile` in den Editor ([170], Befund 16.11.:
|
||||
// vorher wurde die Datei hinter dem Startbildschirm geladen bzw. wartete auf eine Rückfrage, die dort nicht angezeigt wird).
|
||||
const chosenRef = useRef(onProjectFileChosen);
|
||||
chosenRef.current = onProjectFileChosen;
|
||||
const launchRef = useRef(onLaunchFile);
|
||||
launchRef.current = onLaunchFile;
|
||||
useEffect(() => {
|
||||
const api = window.dossierLaunch;
|
||||
if (!api) return;
|
||||
const open = (f: LaunchProject) => chosenRef.current(new File([f.text], f.name), f.path);
|
||||
const open = (f: LaunchProject) => {
|
||||
const wasBooting = launchRef.current?.().wasBooting ?? false;
|
||||
chosenRef.current(new File([f.text], f.name), f.path, !wasBooting);
|
||||
};
|
||||
void api.takeOpenFile().then((f) => f && open(f));
|
||||
return api.onOpenFile(open);
|
||||
}, []);
|
||||
|
||||
Reference in new issue
Block a user