Skip to content

Commit af9f2b3

Browse files
authored
Merge pull request #35 from ut-code/terminal-copy
ターミナルでctrl+cでコピーできるようにした
2 parents b23aa76 + 32aadbb commit af9f2b3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

app/terminal/terminal.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ export function useTerminal(props: TerminalProps) {
121121

122122
term.open(terminalRef.current);
123123

124+
// https://github.com/xtermjs/xterm.js/issues/2478
125+
// my.code();ではCtrl+Cでのkeyboardinterruptは要らないので、コピーペーストに置き換えてしまう
126+
term.attachCustomKeyEventHandler((arg) => {
127+
if (arg.ctrlKey && (arg.key === "c" || arg.key === "x") && arg.type === "keydown") {
128+
const selection = term.getSelection();
129+
if (selection) {
130+
navigator.clipboard.writeText(selection);
131+
return false;
132+
}
133+
}
134+
if (arg.ctrlKey && arg.key === "v" && arg.type === "keydown") {
135+
return false;
136+
}
137+
return true;
138+
});
139+
124140
setTermReady(true);
125141
onReadyRef.current?.();
126142
}

0 commit comments

Comments
 (0)