Fix for Mac double-pasting

This commit is contained in:
Andy Dixon
2026-04-23 11:39:47 +01:00
parent 382f3ca8af
commit 9577b829a0
5 changed files with 28 additions and 0 deletions
+9
View File
@@ -349,6 +349,14 @@
}, },
), ),
); );
body.appendChild(
this._settingField(
"toggle",
"useNativePaste",
"Use native paste",
p.useNativePaste === true,
),
);
} }
/** /**
@@ -1022,6 +1030,7 @@
"defaultFontSize", "defaultFontSize",
"defaultScrollback", "defaultScrollback",
"defaultCursorStyle", "defaultCursorStyle",
"useNativePaste",
]; ];
for (const field of fields) { for (const field of fields) {
+15
View File
@@ -84,6 +84,14 @@
const attachPasteGuard = () => { const attachPasteGuard = () => {
const inputEl = term.textarea || container.querySelector("textarea"); const inputEl = term.textarea || container.querySelector("textarea");
if (!inputEl) return; if (!inputEl) return;
inputEl.addEventListener("keydown", (e) => {
const mod = e.ctrlKey || e.metaKey;
if (!mod || e.key !== "v") return;
// Block the native paste when we handle Cmd/Ctrl+V ourselves.
if (!suppressPasteEvent) return;
e.preventDefault();
e.stopPropagation();
});
inputEl.addEventListener("paste", (e) => { inputEl.addEventListener("paste", (e) => {
if (!suppressPasteEvent) return; if (!suppressPasteEvent) return;
e.preventDefault(); e.preventDefault();
@@ -182,7 +190,14 @@
// Cmd/Ctrl+V — paste from clipboard // Cmd/Ctrl+V — paste from clipboard
if (mod && e.key === "v" && e.type === "keydown") { if (mod && e.key === "v" && e.type === "keydown") {
const prefs = this.app.state.preferences || {};
if (prefs.useNativePaste === true) {
suppressPasteEvent = false;
return true;
}
suppressPasteEvent = true; suppressPasteEvent = true;
e.preventDefault();
e.stopPropagation();
setTimeout(() => { setTimeout(() => {
suppressPasteEvent = false; suppressPasteEvent = false;
}, 250); }, 250);
+2
View File
@@ -12,6 +12,7 @@ export namespace models {
defaultFontSize: number; defaultFontSize: number;
defaultScrollback: number; defaultScrollback: number;
defaultCursorStyle: string; defaultCursorStyle: string;
useNativePaste: boolean;
static createFrom(source: any = {}) { static createFrom(source: any = {}) {
return new AppPreferences(source); return new AppPreferences(source);
@@ -30,6 +31,7 @@ export namespace models {
this.defaultFontSize = source["defaultFontSize"]; this.defaultFontSize = source["defaultFontSize"];
this.defaultScrollback = source["defaultScrollback"]; this.defaultScrollback = source["defaultScrollback"];
this.defaultCursorStyle = source["defaultCursorStyle"]; this.defaultCursorStyle = source["defaultCursorStyle"];
this.useNativePaste = source["useNativePaste"];
} }
} }
export class AuditEntry { export class AuditEntry {
+1
View File
@@ -49,6 +49,7 @@ func DefaultAppPreferences() AppPreferences {
DefaultFontSize: DefaultFontSize, DefaultFontSize: DefaultFontSize,
DefaultScrollback: DefaultScrollback, DefaultScrollback: DefaultScrollback,
DefaultCursorStyle: DefaultCursorStyle, DefaultCursorStyle: DefaultCursorStyle,
UseNativePaste: false,
} }
} }
+1
View File
@@ -263,6 +263,7 @@ type AppPreferences struct {
DefaultFontSize int `json:"defaultFontSize"` DefaultFontSize int `json:"defaultFontSize"`
DefaultScrollback int `json:"defaultScrollback"` DefaultScrollback int `json:"defaultScrollback"`
DefaultCursorStyle string `json:"defaultCursorStyle"` DefaultCursorStyle string `json:"defaultCursorStyle"`
UseNativePaste bool `json:"useNativePaste"`
} }
// AuditEntry records an auditable action within the application. // AuditEntry records an auditable action within the application.