feat(tui): Added Alt+Shift+C keyboard shortcut to copy prompt to clipboard

This commit is contained in:
Scott Hyndman
2026-02-13 05:54:10 -05:00
committed by can1357
parent 1f8a61ff6a
commit be20f44edb
2 changed files with 27 additions and 1 deletions
@@ -19,6 +19,8 @@ export class CustomEditor extends Editor {
onQuestionMark?: () => void;
onCapsLock?: () => void;
onAltP?: () => void;
/** Called when Alt+Shift+C is pressed to copy prompt to clipboard. */
onCopyPrompt?: () => void;
/** Called when Ctrl+V is pressed. Returns true if handled (image found), false to fall through to text paste. */
onCtrlV?: () => Promise<boolean>;
/** Called when Alt+Up is pressed (dequeue keybinding). */
@@ -150,6 +152,12 @@ export class CustomEditor extends Editor {
return;
}
// Intercept Alt+Shift+C to copy prompt to clipboard
if (matchesKey(data, "alt+shift+c") && this.onCopyPrompt) {
this.onCopyPrompt();
return;
}
// Intercept ? when editor is empty to show hotkeys
if (data === "?" && this.getText().length === 0 && this.onQuestionMark) {
this.onQuestionMark();
@@ -1,6 +1,6 @@
import * as fs from "node:fs/promises";
import type { AgentMessage } from "@oh-my-pi/pi-agent-core";
import { readImageFromClipboard } from "@oh-my-pi/pi-natives";
import { copyToClipboard, readImageFromClipboard } from "@oh-my-pi/pi-natives";
import { $env } from "@oh-my-pi/pi-utils";
import type { SettingPath, SettingValue } from "../../config/settings";
import { settings } from "../../config/settings";
@@ -74,6 +74,7 @@ export class InputController {
this.ctx.editor.onCtrlG = () => void this.openExternalEditor();
this.ctx.editor.onQuestionMark = () => this.ctx.handleHotkeysCommand();
this.ctx.editor.onCtrlV = () => this.handleImagePaste();
this.ctx.editor.onCopyPrompt = () => this.handleCopyPrompt();
// Wire up extension shortcuts
this.registerExtensionShortcuts();
@@ -664,6 +665,23 @@ export class InputController {
}
}
/** Copy current prompt text to system clipboard. */
handleCopyPrompt(): void {
const text = this.ctx.editor.getText();
if (!text) {
this.ctx.showStatus("Nothing to copy");
return;
}
copyToClipboard(text)
.then(() => {
const preview = text.length > 30 ? `${text.slice(0, 30)}...` : text;
this.ctx.showStatus(`Copied: ${preview}`);
})
.catch(() => {
this.ctx.showWarning("Failed to copy to clipboard");
});
}
cycleThinkingLevel(): void {
const newLevel = this.ctx.session.cycleThinkingLevel();
if (newLevel === undefined) {