-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #418 from mre/feat/copy-snippet
Add an ability to copy saved snippet to the clipboard
- Loading branch information
Showing
8 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as vscode from "vscode"; | ||
import { getConfig } from "./config"; | ||
|
||
export async function copySnippet(content: string): Promise<void> { | ||
try { | ||
await vscode.env.clipboard.writeText(content); | ||
|
||
if (getConfig("showCopySuccessNotification")) { | ||
await showNotification(); | ||
} | ||
} catch { | ||
vscode.window.showErrorMessage( | ||
"Failed to copy the snippet to the clipboard" | ||
); | ||
} | ||
} | ||
async function showNotification() { | ||
const doNotShowAgain = await vscode.window.showInformationMessage( | ||
"The snippet was copied to the clipboard", | ||
{ modal: false }, | ||
"Do not show again" | ||
); | ||
|
||
if (doNotShowAgain) { | ||
const config = vscode.workspace.getConfiguration("snippet"); | ||
await config.update( | ||
"showCopySuccessNotification", | ||
false, | ||
vscode.ConfigurationTarget.Global | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters