Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions frontend/app/view/term/term-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { boundNumber, fireAndForget, stringToBase64 } from "@/util/util";
import * as jotai from "jotai";
import * as React from "react";
import { getBlockingCommand } from "./shellblocking";
import { computeTheme, DefaultTermTheme } from "./termutil";
import { computeTheme, DefaultTermTheme, trimTerminalSelection } from "./termutil";
import { TermWrap, WebGLSupported } from "./termwrap";

export class TermViewModel implements ViewModel {
Expand Down Expand Up @@ -750,10 +750,13 @@ export class TermViewModel implements ViewModel {
} else if (keyutil.checkKeyPressed(waveEvent, "Ctrl:Shift:c")) {
event.preventDefault();
event.stopPropagation();
const sel = this.termRef.current?.terminal.getSelection();
let sel = this.termRef.current?.terminal.getSelection();
if (!sel) {
return false;
}
if (globalStore.get(getSettingsKeyAtom("term:trimtrailingwhitespace")) !== false) {
sel = trimTerminalSelection(sel);
}
navigator.clipboard.writeText(sel);
return false;
} else if (keyutil.checkKeyPressed(waveEvent, "Cmd:k")) {
Expand Down Expand Up @@ -829,7 +832,11 @@ export class TermViewModel implements ViewModel {
label: "Copy",
click: () => {
if (selection) {
navigator.clipboard.writeText(selection);
const text =
globalStore.get(getSettingsKeyAtom("term:trimtrailingwhitespace")) !== false
? trimTerminalSelection(selection)
: selection;
navigator.clipboard.writeText(text);
}
},
});
Expand Down
7 changes: 7 additions & 0 deletions frontend/app/view/term/termutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { colord } from "colord";

export type GenClipboardItem = { text?: string; image?: Blob };

export function trimTerminalSelection(text: string): string {
return text
.split("\n")
.map((line) => line.trimEnd())
.join("\n");
}

export function normalizeCursorStyle(cursorStyle: string): TermTypes.Terminal["options"]["cursorStyle"] {
if (cursorStyle === "underline" || cursorStyle === "bar") {
return cursorStyle;
Expand Down
7 changes: 6 additions & 1 deletion frontend/app/view/term/termwrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
extractAllClipboardData,
normalizeCursorStyle,
quoteForPosixShell,
trimTerminalSelection,
} from "./termutil";

const dlog = debug("wave:termwrap");
Expand Down Expand Up @@ -380,6 +381,7 @@ export class TermWrap {

async initTerminal() {
const copyOnSelectAtom = getSettingsKeyAtom("term:copyonselect");
const trimTrailingWhitespaceAtom = getSettingsKeyAtom("term:trimtrailingwhitespace");
this.toDispose.push(this.terminal.onData(this.handleTermData.bind(this)));
this.toDispose.push(
this.terminal.onSelectionChange(
Expand All @@ -393,8 +395,11 @@ export class TermWrap {
if (active != null && active.closest(".search-container") != null) {
return;
}
const selectedText = this.terminal.getSelection();
let selectedText = this.terminal.getSelection();
if (selectedText.length > 0) {
if (globalStore.get(trimTrailingWhitespaceAtom) !== false) {
selectedText = trimTerminalSelection(selectedText);
}
navigator.clipboard.writeText(selectedText);
}
})
Expand Down
1 change: 1 addition & 0 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ declare global {
"term:osc52"?: string;
"term:durable"?: boolean;
"term:showsplitbuttons"?: boolean;
"term:trimtrailingwhitespace"?: boolean;
"editor:minimapenabled"?: boolean;
"editor:stickyscrollenabled"?: boolean;
"editor:wordwrap"?: boolean;
Expand Down
1 change: 1 addition & 0 deletions pkg/wconfig/defaultconfig/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"term:cursor": "block",
"term:cursorblink": false,
"term:copyonselect": true,
"term:trimtrailingwhitespace": true,
"term:durable": false,
"waveai:showcloudmodes": true,
"waveai:defaultmode": "waveai@balanced",
Expand Down
1 change: 1 addition & 0 deletions pkg/wconfig/metaconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
ConfigKey_TermOsc52 = "term:osc52"
ConfigKey_TermDurable = "term:durable"
ConfigKey_TermShowSplitButtons = "term:showsplitbuttons"
ConfigKey_TermTrimTrailingWhitespace = "term:trimtrailingwhitespace"

ConfigKey_EditorMinimapEnabled = "editor:minimapenabled"
ConfigKey_EditorStickyScrollEnabled = "editor:stickyscrollenabled"
Expand Down
5 changes: 3 additions & 2 deletions pkg/wconfig/settingsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ type SettingsType struct {
TermBellSound *bool `json:"term:bellsound,omitempty"`
TermBellIndicator *bool `json:"term:bellindicator,omitempty"`
TermOsc52 string `json:"term:osc52,omitempty" jsonschema:"enum=focus,enum=always"`
TermDurable *bool `json:"term:durable,omitempty"`
TermShowSplitButtons bool `json:"term:showsplitbuttons,omitempty"`
TermDurable *bool `json:"term:durable,omitempty"`
TermShowSplitButtons bool `json:"term:showsplitbuttons,omitempty"`
TermTrimTrailingWhitespace *bool `json:"term:trimtrailingwhitespace,omitempty"`

EditorMinimapEnabled bool `json:"editor:minimapenabled,omitempty"`
EditorStickyScrollEnabled bool `json:"editor:stickyscrollenabled,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions schema/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
"term:showsplitbuttons": {
"type": "boolean"
},
"term:trimtrailingwhitespace": {
"type": "boolean"
},
"editor:minimapenabled": {
"type": "boolean"
},
Expand Down