Skip to content

Commit 7f5463c

Browse files
committed
Implement Ctrl+K
Fixes #7
1 parent 1ac1aae commit 7f5463c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/client.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { webLinksHandler } from "./lib/addons";
1515
import { initiateRemoteCommunicationChannelSocket } from "./lib/remote";
1616
import { Emitter } from '@gitpod/gitpod-protocol/lib/util/event';
1717
import { DisposableCollection } from '@gitpod/gitpod-protocol/lib/util/disposable';
18-
import { debounce } from './lib/helpers';
18+
import { debounce, isWindows } from './lib/helpers';
1919

2020
const onDidChangeState = new Emitter<void>();
2121
let state: IDEFrontendState = "initializing" as IDEFrontendState;
@@ -129,23 +129,22 @@ async function createTerminal(element: HTMLElement, toDispose: DisposableCollect
129129
element.removeChild(element.children[0]);
130130
}
131131

132-
const isWindows =
133-
["Windows", "Win16", "Win32", "WinCE"].indexOf(navigator.platform) >= 0;
134-
135132
const { Terminal } = (await import("xterm"));
136133

137134
term = new Terminal({
138135
windowsMode: isWindows,
139136
fontFamily: defaultFonts.join(", "),
140137
allowProposedApi: true
141138
} as ITerminalOptions);
139+
142140
toDispose.push(term);
143141

144142
window.terminal = term;
145143
term.onResize(async (size) => {
146144
await resizeRemoteTerminal(size, pid);
147145
console.info(`Resized remote terminal to ${size.cols}x${size.rows}`);
148146
});
147+
149148
protocol = location.protocol === "https:" ? "wss://" : "ws://";
150149
socketURL = `${protocol + location.hostname + (location.port ? ":" + location.port : "")
151150
}/terminals/`;
@@ -265,4 +264,14 @@ window.gitpod.ideService = {
265264
}
266265
return toDispose;
267266
}
268-
};
267+
};
268+
269+
document.addEventListener("keydown", ((event) => {
270+
const ctrlCmd = isWindows ? event.ctrlKey : event.metaKey;
271+
if (ctrlCmd && event.key === "k") {
272+
event.preventDefault();
273+
if (term) {
274+
term.clear();
275+
}
276+
}
277+
}));

src/lib/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ export const debounce = (func: () => void, wait: number, trailing: boolean): ()
2929
timeout = setTimeout(later, wait);
3030
};
3131
}
32+
33+
export const isWindows =
34+
["Windows", "Win16", "Win32", "WinCE"].includes(navigator.platform);

0 commit comments

Comments
 (0)