From 2b77ed19b6fd9f721be68b76cceee749999a37a8 Mon Sep 17 00:00:00 2001 From: filippofinke Date: Wed, 1 Mar 2023 09:17:31 +0100 Subject: [PATCH] feat: allow the user to copy text to the clipboard --- src/taskpane/components/App.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/taskpane/components/App.tsx b/src/taskpane/components/App.tsx index 117e2bd..ed991d6 100644 --- a/src/taskpane/components/App.tsx +++ b/src/taskpane/components/App.tsx @@ -4,7 +4,7 @@ import { Configuration, OpenAIApi } from "openai"; import Center from "./Center"; import Container from "./Container"; import Login from "./Login"; -/* global Word, localStorage */ +/* global Word, localStorage, navigator */ export default function App() { const [apiKey, setApiKey] = React.useState(""); @@ -52,11 +52,16 @@ export default function App() { const onInsert = async () => { await Word.run(async (context) => { - context.document.body.insertHtml(generatedText, "Start"); + const selection = context.document.getSelection(); + selection.insertText(generatedText, "Start"); await context.sync(); }); }; + const onCopy = async () => { + navigator.clipboard.writeText(generatedText); + }; + return ( {apiKey ? ( @@ -92,6 +97,9 @@ export default function App() { Insert text + + Copy text + )}