implement copy on select for terminal (#1029)

This commit is contained in:
Mike Sawka 2024-10-14 10:05:38 -07:00 committed by GitHub
parent 31535404f5
commit a15b339f39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 23 additions and 2 deletions

View File

@ -5,7 +5,7 @@ import { getFileSubject } from "@/app/store/wps";
import { sendWSCommand } from "@/app/store/ws"; import { sendWSCommand } from "@/app/store/ws";
import { RpcApi } from "@/app/store/wshclientapi"; import { RpcApi } from "@/app/store/wshclientapi";
import { WindowRpcClient } from "@/app/store/wshrpcutil"; import { WindowRpcClient } from "@/app/store/wshrpcutil";
import { PLATFORM, WOS, atoms, fetchWaveFile, globalStore, openLink } from "@/store/global"; import { PLATFORM, WOS, atoms, fetchWaveFile, getSettingsKeyAtom, globalStore, openLink } from "@/store/global";
import * as services from "@/store/services"; import * as services from "@/store/services";
import * as util from "@/util/util"; import * as util from "@/util/util";
import { base64ToArray, fireAndForget } from "@/util/util"; import { base64ToArray, fireAndForget } from "@/util/util";
@ -134,7 +134,19 @@ export class TermWrap {
} }
async initTerminal() { async initTerminal() {
const copyOnSelectAtom = getSettingsKeyAtom("term:copyonselect");
this.terminal.onData(this.handleTermData.bind(this)); this.terminal.onData(this.handleTermData.bind(this));
this.terminal.onSelectionChange(
debounce(50, () => {
if (!globalStore.get(copyOnSelectAtom)) {
return;
}
const selectedText = this.terminal.getSelection();
if (selectedText.length > 0) {
navigator.clipboard.writeText(selectedText);
}
})
);
this.mainFileSubject = getFileSubject(this.blockId, TermFileName); this.mainFileSubject = getFileSubject(this.blockId, TermFileName);
this.mainFileSubject.subscribe(this.handleNewFileSubjectData.bind(this)); this.mainFileSubject.subscribe(this.handleNewFileSubjectData.bind(this));
try { try {

View File

@ -9,4 +9,9 @@
overflow: hidden; overflow: hidden;
padding: 0; padding: 0;
margin: 0; margin: 0;
// try to force pixel alignment to prevent
// subpixel rendering artifacts
transform: translate3d(0, 0, 0);
will-change: transform;
} }

View File

@ -445,6 +445,7 @@ declare global {
"term:localshellpath"?: string; "term:localshellpath"?: string;
"term:localshellopts"?: string[]; "term:localshellopts"?: string[];
"term:scrollback"?: number; "term:scrollback"?: number;
"term:copyonselect"?: boolean;
"editor:minimapenabled"?: boolean; "editor:minimapenabled"?: boolean;
"editor:stickyscrollenabled"?: boolean; "editor:stickyscrollenabled"?: boolean;
"web:*"?: boolean; "web:*"?: boolean;

View File

@ -11,5 +11,6 @@
"web:defaulturl": "https://github.com/wavetermdev/waveterm", "web:defaulturl": "https://github.com/wavetermdev/waveterm",
"web:defaultsearch": "https://www.google.com/search?q={query}", "web:defaultsearch": "https://www.google.com/search?q={query}",
"window:tilegapsize": 3, "window:tilegapsize": 3,
"telemetry:enabled": true "telemetry:enabled": true,
"term:copyonselect": true
} }

View File

@ -26,6 +26,7 @@ const (
ConfigKey_TermLocalShellPath = "term:localshellpath" ConfigKey_TermLocalShellPath = "term:localshellpath"
ConfigKey_TermLocalShellOpts = "term:localshellopts" ConfigKey_TermLocalShellOpts = "term:localshellopts"
ConfigKey_TermScrollback = "term:scrollback" ConfigKey_TermScrollback = "term:scrollback"
ConfigKey_TermCopyOnSelect = "term:copyonselect"
ConfigKey_EditorMinimapEnabled = "editor:minimapenabled" ConfigKey_EditorMinimapEnabled = "editor:minimapenabled"
ConfigKey_EditorStickyScrollEnabled = "editor:stickyscrollenabled" ConfigKey_EditorStickyScrollEnabled = "editor:stickyscrollenabled"

View File

@ -60,6 +60,7 @@ type SettingsType struct {
TermLocalShellPath string `json:"term:localshellpath,omitempty"` TermLocalShellPath string `json:"term:localshellpath,omitempty"`
TermLocalShellOpts []string `json:"term:localshellopts,omitempty"` TermLocalShellOpts []string `json:"term:localshellopts,omitempty"`
TermScrollback *int64 `json:"term:scrollback,omitempty"` TermScrollback *int64 `json:"term:scrollback,omitempty"`
TermCopyOnSelect *bool `json:"term:copyonselect,omitempty"`
EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"` EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"`
EditorStickyScrollEnabled bool `json:"editor:stickyscrollenabled,omitempty"` EditorStickyScrollEnabled bool `json:"editor:stickyscrollenabled,omitempty"`