@@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2
2
import { httpLink , wsLink , splitLink , createWSClient } from "@trpc/client" ;
3
3
import { Mode } from "@wingconsole/design-system" ;
4
4
import { Trace } from "@wingconsole/server" ;
5
+ import { useEffect , useMemo } from "react" ;
5
6
6
7
import { App } from "./App.js" ;
7
8
import { AppContext } from "./AppContext.js" ;
@@ -58,7 +59,48 @@ export const Console = ({
58
59
59
60
let windowTitle = title ?? "Wing Console" ;
60
61
61
- const appMode = layout === LayoutType . Default ? "local" : "remote" ;
62
+ const appMode = useMemo ( ( ) => {
63
+ return layout === LayoutType . Default || layout === LayoutType . Vscode
64
+ ? "local"
65
+ : "remote" ;
66
+ } , [ layout ] ) ;
67
+
68
+ // This is a workaround for handling copy/paste when running in VSCode
69
+ // There is an open issue in VSCode repo: https://github.com/microsoft/vscode/issues/129178
70
+ useEffect ( ( ) => {
71
+ if ( layout !== LayoutType . Vscode ) {
72
+ return ;
73
+ }
74
+
75
+ const vscodeCommands = ( event : KeyboardEvent ) => {
76
+ if ( ! ( event . ctrlKey || event . metaKey ) ) {
77
+ return ;
78
+ }
79
+ switch ( event . code ) {
80
+ case "KeyC" : {
81
+ document . execCommand ( "copy" ) ;
82
+ break ;
83
+ }
84
+ case "KeyX" : {
85
+ document . execCommand ( "cut" ) ;
86
+ break ;
87
+ }
88
+ case "KeyV" : {
89
+ document . execCommand ( "paste" ) ;
90
+ break ;
91
+ }
92
+ case "KeyA" : {
93
+ document . execCommand ( "selectAll" ) ;
94
+ }
95
+ }
96
+ } ;
97
+
98
+ window . addEventListener ( "keydown" , vscodeCommands ) ;
99
+ return ( ) => {
100
+ window . removeEventListener ( "keydown" , vscodeCommands ) ;
101
+ } ;
102
+ } , [ layout ] ) ;
103
+
62
104
return (
63
105
< AppContext . Provider value = { { appMode, title : windowTitle } } >
64
106
< trpc . Provider client = { trpcClient } queryClient = { queryClient } >
0 commit comments