Skip to content

Commit f289a19

Browse files
authored
Merge pull request #53 from aws/dogusata/add-check-statement-to-clipboard-access
Dogusata/add check statement to clipboard access
2 parents ec76d54 + ad7c9b8 commit f289a19

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@aws/mynah-ui",
33
"displayName": "AWS Mynah UI",
4-
"version": "4.10.0",
4+
"version": "4.10.1",
55
"description": "AWS Toolkit VSCode and Intellij IDE Extension Mynah UI",
66
"publisher": "Amazon Web Services",
77
"license": "Apache License 2.0",

src/components/syntax-highlighter.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -252,35 +252,31 @@ export class SyntaxHighlighter {
252252
type: 'block'
253253
});
254254

255-
private readonly copyToClipboard = (
255+
private readonly copyToClipboard = async (
256256
textToSendClipboard: string,
257257
type?: CodeSelectionType,
258258
notificationText?: string,
259-
): void => {
259+
): Promise<void> => {
260260
if (!document.hasFocus()) {
261261
window.focus();
262262
}
263-
navigator.clipboard
264-
.writeText(textToSendClipboard)
265-
.then(() => {
266-
if (this.props?.onCopiedToClipboard !== undefined) {
267-
this.props?.onCopiedToClipboard(
268-
type,
269-
textToSendClipboard,
270-
this.props.index
271-
);
272-
}
273-
if (notificationText !== undefined) {
274-
// eslint-disable no-new
275-
new Notification({
276-
content: notificationText,
277-
title: Config.getInstance().config.texts.copyToClipboard,
278-
duration: 2000,
279-
}).notify();
280-
}
281-
})
282-
.catch(e => {
283-
//
284-
});
263+
try {
264+
await navigator.clipboard.writeText(textToSendClipboard);
265+
} finally {
266+
if (this.props?.onCopiedToClipboard != null) {
267+
this.props?.onCopiedToClipboard(
268+
type,
269+
textToSendClipboard,
270+
this.props.index
271+
);
272+
}
273+
if (notificationText != null) {
274+
new Notification({
275+
content: notificationText,
276+
title: Config.getInstance().config.texts.copyToClipboard,
277+
duration: 2000,
278+
}).notify();
279+
}
280+
}
285281
};
286282
}

0 commit comments

Comments
 (0)