From 6a22d8dbc3bce549ef4021fbb85cf6fff3f95760 Mon Sep 17 00:00:00 2001 From: java4life Date: Fri, 12 Jul 2024 04:43:24 +0200 Subject: [PATCH 1/2] Adde quick save option (ctrl-s) --- src/main.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.ts b/src/main.ts index c857f51..5f89968 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,6 +29,7 @@ let embedElement: Element; let choices: string[]; let controllers: AbortController[]; let completionCallback: (() => Promise) | null; +let fileHandle: FileSystemFileHandle; const client = new OpenAI({ baseURL: BASE_URL, @@ -209,6 +210,27 @@ const quill = new Quill("#editor", { await generate(); }, }, + handleS: { + // Ctrl/Cmd+s + key: "s", + shortKey: true, + collapsed: true, + handler: async () => { + let text = quill.getText(0, quill.getLength()); + if( fileHandle === undefined) { + fileHandle = await window.showSaveFilePicker({ + suggestedName: 'file.txt', + types: [{ + description: 'Text Files', + accept: {'text/plain': ['.txt']} + }] + }); + } + const writableStream = await fileHandle.createWritable(); + await writableStream.write(text); + await writableStream.close(); + }, + }, }, }, }, From 45f85fde181b20bd925a9f5574d98b05abe15ffd Mon Sep 17 00:00:00 2001 From: java4life Date: Fri, 12 Jul 2024 04:43:24 +0200 Subject: [PATCH 2/2] Added quick save option (ctrl-s) --- src/main.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.ts b/src/main.ts index c857f51..5f89968 100644 --- a/src/main.ts +++ b/src/main.ts @@ -29,6 +29,7 @@ let embedElement: Element; let choices: string[]; let controllers: AbortController[]; let completionCallback: (() => Promise) | null; +let fileHandle: FileSystemFileHandle; const client = new OpenAI({ baseURL: BASE_URL, @@ -209,6 +210,27 @@ const quill = new Quill("#editor", { await generate(); }, }, + handleS: { + // Ctrl/Cmd+s + key: "s", + shortKey: true, + collapsed: true, + handler: async () => { + let text = quill.getText(0, quill.getLength()); + if( fileHandle === undefined) { + fileHandle = await window.showSaveFilePicker({ + suggestedName: 'file.txt', + types: [{ + description: 'Text Files', + accept: {'text/plain': ['.txt']} + }] + }); + } + const writableStream = await fileHandle.createWritable(); + await writableStream.write(text); + await writableStream.close(); + }, + }, }, }, },