mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 11:07:04 +00:00
feat(macos): trigger Apple Intelligence writing tools from the editor
This commit is contained in:
1 parent
fe39274ed7
commit
9e310a34bb
5 files changed
+108
-2
No files matched your search
@@ -23,11 +23,16 @@ import { WIDTH_OPTIONS } from "../width";
|
||||
import { bodyNumber, chapterKind, partNumber, partRoman } from "../model/book";
|
||||
import { saveBook } from "../library";
|
||||
import { useEscapeLayer } from "../escape";
|
||||
import { isDesktop } from "../ipc";
|
||||
import { isDesktop, runWritingTool } from "../ipc";
|
||||
import { useCompact } from "../useMedia";
|
||||
import { issueSignature, rememberWord, runProof } from "../proofing";
|
||||
import { runExport } from "../export/run";
|
||||
|
||||
const WRITING_TOOLS: Record<string, "Proofread" | "Rewrite"> = {
|
||||
KeyF: "Proofread",
|
||||
KeyR: "Rewrite",
|
||||
};
|
||||
|
||||
export function EditorView() {
|
||||
const book = useBook((s) => s.book);
|
||||
const activeChapterId = useBook((s) => s.activeChapterId);
|
||||
@@ -172,6 +177,10 @@ export function EditorView() {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
switchChapter(e.shiftKey ? -1 : 1);
|
||||
} else if (e.shiftKey && e.altKey && !e.metaKey && !e.ctrlKey && WRITING_TOOLS[e.code]) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
runWritingTool(WRITING_TOOLS[e.code]).catch(() => {});
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKey, true);
|
||||
|
||||
@@ -2,6 +2,11 @@ import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
export const isDesktop = typeof window !== "undefined" && "__TAURI_INTERNALS__" in window;
|
||||
|
||||
export async function runWritingTool(tool: "Proofread" | "Rewrite"): Promise<void> {
|
||||
if (!isDesktop) return;
|
||||
await invoke("run_writing_tool", { tool });
|
||||
}
|
||||
|
||||
export interface ImageInput {
|
||||
path: string;
|
||||
data: string;
|
||||
|
||||
Reference in new issue
Block a user