Skip to content

Commit b6fe2b2

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

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
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/hooks/useRemoteConnection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const useRemoteConnection = () => {
7070
}
7171
}, []);
7272

73-
const sendCombo = useCallback((msg: string[]) => {
73+
const sendCombo = useCallback((msg: readonly string[]) => {
7474
if (wsRef.current?.readyState === WebSocket.OPEN) {
7575
wsRef.current.send(JSON.stringify({
7676
type: "combo",

src/routes/trackpad.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@ export const Route = createFileRoute('/trackpad')({
1212
component: TrackpadPage,
1313
})
1414

15+
const COPY_COMBO = ["control", "c"] as const;
16+
const PASTE_COMBO = ["control", "v"] as const;
17+
1518
function TrackpadPage() {
1619
const [scrollMode, setScrollMode] = useState(false);
1720
const [modifier, setModifier] = useState<ModifierState>("Release");
1821
const [buffer, setBuffer] = useState<string[]>([]);
1922
const bufferText = buffer.join(" + ");
2023
const hiddenInputRef = useRef<HTMLInputElement>(null);
2124
const isComposingRef = useRef(false);
22-
25+
2326
// Load Client Settings
2427
const [sensitivity] = useState(() => {
2528
if (typeof window === 'undefined') return 1.0;
2629
const s = localStorage.getItem('rein_sensitivity');
2730
return s ? parseFloat(s) : 1.0;
2831
});
29-
32+
3033
const [invertScroll] = useState(() => {
3134
if (typeof window === 'undefined') return false;
3235
const s = localStorage.getItem('rein_invert');
@@ -49,7 +52,7 @@ function TrackpadPage() {
4952

5053
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
5154
const key = e.key.toLowerCase();
52-
55+
5356
if (modifier !== "Release") {
5457
if (key === 'backspace') {
5558
e.preventDefault();
@@ -76,7 +79,7 @@ function TrackpadPage() {
7679
};
7780

7881
const handleModifierState = () => {
79-
switch(modifier){
82+
switch (modifier) {
8083
case "Active":
8184
if (buffer.length > 0) {
8285
setModifier("Hold");
@@ -97,7 +100,7 @@ function TrackpadPage() {
97100

98101
const handleModifier = (key: string) => {
99102
console.log(`handleModifier called with key: ${key}, current modifier: ${modifier}, buffer:`, buffer);
100-
103+
101104
if (modifier === "Hold") {
102105
const comboKeys = [...buffer, key];
103106
console.log(`Sending combo:`, comboKeys);
@@ -139,7 +142,7 @@ function TrackpadPage() {
139142
// Don't send text during modifier mode
140143
if (modifier !== "Release") {
141144
handleModifier(val);
142-
}else{
145+
} else {
143146
sendText(val);
144147
}
145148
(e.target as HTMLInputElement).value = '';
@@ -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)