Skip to content

Commit c5c9959

Browse files
Nakshatra SharmaNakshatra Sharma
authored andcommitted
Add copy and paste shortcuts to trackpad toolbar
1 parent 0cbf82f commit c5c9959

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/components/Trackpad/ControlBar.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ interface ControlBarProps {
1010
onRightClick: () => void;
1111
onKeyboardToggle: () => void;
1212
onModifierToggle: () => void;
13+
onCopy: () => void;
14+
onPaste: () => void;
1315
}
1416

1517
export const ControlBar: React.FC<ControlBarProps> = ({
@@ -21,6 +23,8 @@ export const ControlBar: React.FC<ControlBarProps> = ({
2123
onRightClick,
2224
onKeyboardToggle,
2325
onModifierToggle,
26+
onCopy,
27+
onPaste,
2428
}) => {
2529
const handleInteraction = (e: React.PointerEvent, action: () => void) => {
2630
e.preventDefault();
@@ -62,11 +66,13 @@ export const ControlBar: React.FC<ControlBarProps> = ({
6266
</button>
6367
<button
6468
className="btn btn-sm btn-outline"
69+
onPointerDown={(e) => handleInteraction(e, onCopy)}
6570
>
6671
Copy
6772
</button>
6873
<button
6974
className="btn btn-sm btn-outline"
75+
onPointerDown={(e) => handleInteraction(e, onPaste)}
7076
>
7177
Paste
7278
</button>
@@ -98,4 +104,4 @@ export const ControlBar: React.FC<ControlBarProps> = ({
98104
</button>
99105
</div>
100106
);
101-
};
107+
};

src/routes/trackpad.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ function TrackpadPage() {
1919
const bufferText = buffer.join(" + ");
2020
const hiddenInputRef = useRef<HTMLInputElement>(null);
2121
const isComposingRef = useRef(false);
22-
22+
2323
// Load Client Settings
2424
const [sensitivity] = useState(() => {
2525
if (typeof window === 'undefined') return 1.0;
2626
const s = localStorage.getItem('rein_sensitivity');
2727
return s ? parseFloat(s) : 1.0;
2828
});
29-
29+
3030
const [invertScroll] = useState(() => {
3131
if (typeof window === 'undefined') return false;
3232
const s = localStorage.getItem('rein_invert');
@@ -49,7 +49,7 @@ function TrackpadPage() {
4949

5050
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
5151
const key = e.key.toLowerCase();
52-
52+
5353
if (modifier !== "Release") {
5454
if (key === 'backspace') {
5555
e.preventDefault();
@@ -76,7 +76,7 @@ function TrackpadPage() {
7676
};
7777

7878
const handleModifierState = () => {
79-
switch(modifier){
79+
switch (modifier) {
8080
case "Active":
8181
if (buffer.length > 0) {
8282
setModifier("Hold");
@@ -97,7 +97,7 @@ function TrackpadPage() {
9797

9898
const handleModifier = (key: string) => {
9999
console.log(`handleModifier called with key: ${key}, current modifier: ${modifier}, buffer:`, buffer);
100-
100+
101101
if (modifier === "Hold") {
102102
const comboKeys = [...buffer, key];
103103
console.log(`Sending combo:`, comboKeys);
@@ -139,7 +139,7 @@ function TrackpadPage() {
139139
// Don't send text during modifier mode
140140
if (modifier !== "Release") {
141141
handleModifier(val);
142-
}else{
142+
} else {
143143
sendText(val);
144144
}
145145
(e.target as HTMLInputElement).value = '';
@@ -153,6 +153,9 @@ function TrackpadPage() {
153153
}
154154
};
155155

156+
const COPY_COMBO = ["control", "c"] as const;
157+
const PASTE_COMBO = ["control", "v"] as const;
158+
156159
return (
157160
<div
158161
className="flex flex-col h-full overflow-hidden"
@@ -177,6 +180,8 @@ function TrackpadPage() {
177180
onRightClick={() => handleClick('right')}
178181
onKeyboardToggle={focusInput}
179182
onModifierToggle={handleModifierState}
183+
onCopy={() => sendCombo([...COPY_COMBO])}
184+
onPaste={() => sendCombo([...PASTE_COMBO])}
180185
/>
181186

182187
{/* Extra Keys */}

0 commit comments

Comments
 (0)