Skip to content

Commit

Permalink
feat: allow the user to copy text to the clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
filippofinke committed Mar 1, 2023
1 parent f6e416f commit 2b77ed1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/taskpane/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>("");
Expand Down Expand Up @@ -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 (
<Container>
{apiKey ? (
Expand Down Expand Up @@ -92,6 +97,9 @@ export default function App() {
<DefaultButton iconProps={{ iconName: "Add" }} onClick={onInsert}>
Insert text
</DefaultButton>
<DefaultButton iconProps={{ iconName: "Copy" }} onClick={onCopy}>
Copy text
</DefaultButton>
</Center>
</div>
)}
Expand Down

1 comment on commit 2b77ed1

@vercel
Copy link

@vercel vercel bot commented on 2b77ed1 Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

word-gpt – ./

word-gpt-filippofinke.vercel.app
word-gpt-git-main-filippofinke.vercel.app
word-gpt.vercel.app

Please sign in to comment.