Skip to content

Commit 09d963b

Browse files
committed
feat: keybindings for copy and paste
1 parent 4c65dd2 commit 09d963b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/components/terminal/terminal.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,56 @@ export default class TerminalComponent {
115115
this.terminal.onBell(() => {
116116
this.onBell?.();
117117
});
118+
119+
// Handle copy/paste keybindings
120+
this.setupCopyPasteHandlers();
121+
}
122+
123+
/**
124+
* Setup copy/paste keyboard handlers
125+
*/
126+
setupCopyPasteHandlers() {
127+
// Add keyboard event listener to terminal element
128+
this.terminal.attachCustomKeyEventHandler((event) => {
129+
// Check for Ctrl+Shift+C (copy)
130+
if (event.ctrlKey && event.shiftKey && event.key === "C") {
131+
event.preventDefault();
132+
this.copySelection();
133+
return false;
134+
}
135+
136+
// Check for Ctrl+Shift+V (paste)
137+
if (event.ctrlKey && event.shiftKey && event.key === "V") {
138+
event.preventDefault();
139+
this.pasteFromClipboard();
140+
return false;
141+
}
142+
143+
// Return true to allow normal processing for other keys
144+
return true;
145+
});
146+
}
147+
148+
/**
149+
* Copy selected text to clipboard
150+
*/
151+
copySelection() {
152+
if (!this.terminal?.hasSelection()) return;
153+
const selectedStr = this.terminal?.getSelection();
154+
if (selectedStr && cordova?.plugins?.clipboard) {
155+
cordova.plugins.clipboard.copy(selectedStr);
156+
}
157+
}
158+
159+
/**
160+
* Paste text from clipboard
161+
*/
162+
pasteFromClipboard() {
163+
if (cordova?.plugins?.clipboard) {
164+
cordova.plugins.clipboard.paste((text) => {
165+
this.terminal?.paste(text);
166+
});
167+
}
118168
}
119169

120170
/**

0 commit comments

Comments
 (0)