1- import { ExtensionContext , ViewColumn , WebviewPanel , window } from 'vscode' ;
1+ import { Clipboard , commands , env , ExtensionContext , ViewColumn , WebviewPanel , window } from 'vscode' ;
2+ import { trace } from '../utils/decorator' ;
23import { disposeAll } from '../utils/dispose' ;
34import { BaseWebview } from './baseWebview' ;
45
@@ -15,8 +16,14 @@ export class CodeSnippetWebview extends BaseWebview {
1516 return 'codeSnippetPreviewFocus' ;
1617 }
1718
19+ private readonly clipboard : Clipboard = env . clipboard ;
20+
21+ private activeCodeSnippet : string | undefined ;
22+
1823 public constructor ( context : ExtensionContext ) {
1924 super ( context ) ;
25+
26+ this . context . subscriptions . push ( commands . registerCommand ( 'rest-client.copy-codesnippet' , this . copy , this ) ) ;
2027 }
2128
2229 public async render ( convertResult : string , title : string , lang : string ) {
@@ -52,6 +59,7 @@ export class CodeSnippetWebview extends BaseWebview {
5259 panel . webview . html = this . getHtmlForWebview ( panel , convertResult , lang ) ;
5360
5461 this . setPrviewActiveContext ( true ) ;
62+ this . activeCodeSnippet = convertResult ;
5563
5664 panel . reveal ( ViewColumn . Two ) ;
5765 }
@@ -60,6 +68,13 @@ export class CodeSnippetWebview extends BaseWebview {
6068 disposeAll ( this . panels ) ;
6169 }
6270
71+ @trace ( 'Copy Code Snippet' )
72+ private async copy ( ) {
73+ if ( this . activeCodeSnippet ) {
74+ await this . clipboard . writeText ( this . activeCodeSnippet ) ;
75+ }
76+ }
77+
6378 private getHtmlForWebview ( panel : WebviewPanel , convertResult : string , lang : string ) : string {
6479 const csp = this . getCsp ( ) ;
6580 return `
0 commit comments