Skip to content

Commit

Permalink
support copy on select and paste on right click (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kun Chen committed May 6, 2023
1 parent b68dc39 commit de7e0ad
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
19 changes: 19 additions & 0 deletions apps/terminal/components/Terminal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,28 @@ const Terminal = ({ active, shellName }: { active: boolean; shellName: string })
};
xtermDiv.addEventListener('focus', focusListener);

const mouseUpListener = () => {
if (config.copyOnSelect && xterm.hasSelection()) {
const selectedText = xterm.getSelection();
navigator.clipboard.writeText(selectedText);
}
};
xtermDiv.addEventListener('mouseup', mouseUpListener);

const contextMenuListener = () => {
navigator.clipboard.readText().then((text) => {
if (text) {
xterm.paste(text);
}
});
};
xtermDiv.addEventListener('contextmenu', contextMenuListener);

return () => {
window.removeEventListener('resize', resizeListener);
xtermDiv.removeEventListener('focus', focusListener);
xtermDiv.removeEventListener('mouseup', mouseUpListener);
xtermDiv.removeEventListener('contextmenu', contextMenuListener);

window.TerminalOne?.terminal?.killTerminal(terminalId);
xterm.dispose();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@terminalone/monorepo",
"productName": "Terminal One",
"version": "0.4.0",
"version": "0.5.0",
"description": "A fast, elegant and intelligent cross-platform terminal.",
"author": "Kun Chen",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions packages/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const ConfigTypeContent = {
}),
cursorWidth: t.number,
scrollback: t.number,
copyOnSelect: t.boolean,
fontSize: t.number,
fontFamily: t.string,
fontWeight: t.number,
Expand Down
3 changes: 3 additions & 0 deletions packages/types/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const DEFAULT_CONFIG: ResolvedConfig = {
// Number of lines to keep in the scrollback buffer.
scrollback: 10000,

// Whether to copy text to the clipboard on selection.
copyOnSelect: true,

// Whether to blink the cursor.
cursorBlink: true,

Expand Down

0 comments on commit de7e0ad

Please sign in to comment.