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
39 changes: 17 additions & 22 deletions app/tabs/sessions/Sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import React, { useState, useEffect, useRef, useCallback } from "react";
import {
View,
Text,
ScrollView,
TouchableOpacity,
StyleSheet,
Keyboard,
KeyboardAvoidingView,
Platform,
TextInput,
TouchableWithoutFeedback,
Pressable,
Dimensions,
BackHandler,
AppState,
Expand Down Expand Up @@ -40,16 +34,17 @@ import {
import TabBar from "@/app/tabs/sessions/navigation/TabBar";
import BottomToolbar from "@/app/tabs/sessions/terminal/keyboard/BottomToolbar";
import KeyboardBar from "@/app/tabs/sessions/terminal/keyboard/KeyboardBar";
import { ArrowLeft } from "lucide-react-native";
import { useOrientation } from "@/app/utils/orientation";
import { getMaxKeyboardHeight, getTabBarHeight } from "@/app/utils/responsive";
import {
BACKGROUNDS,
BORDER_COLORS,
BORDERS,
} from "@/app/constants/designTokens";
import { BACKGROUNDS, BORDER_COLORS } from "@/app/constants/designTokens";
import { addKeyCommandListener } from "@/modules/hardware-keyboard";

type ActiveModifiers = {
ctrl: boolean;
alt: boolean;
shift: boolean;
};

export default function Sessions() {
const insets = useSafeAreaInsets();
const router = useRouter();
Expand Down Expand Up @@ -84,6 +79,7 @@ export default function Sessions() {
const [activeModifiers, setActiveModifiers] = useState({
ctrl: false,
alt: false,
shift: false,
});
const [screenDimensions, setScreenDimensions] = useState(
Dimensions.get("window"),
Expand Down Expand Up @@ -516,12 +512,9 @@ export default function Sessions() {
}
};

const handleModifierChange = useCallback(
(modifiers: { ctrl: boolean; alt: boolean }) => {
setActiveModifiers(modifiers);
},
[],
);
const handleModifierChange = useCallback((modifiers: ActiveModifiers) => {
setActiveModifiers(modifiers);
}, []);

const activeSession = sessions.find(
(session) => session.id === activeSessionId,
Expand Down Expand Up @@ -952,7 +945,7 @@ export default function Sessions() {
finalKey = "\x7f";
break;
case "Tab":
finalKey = "\t";
finalKey = activeModifiers.shift ? "\x1b[Z" : "\t";
break;
case "Escape":
finalKey = "\x1b";
Expand Down Expand Up @@ -1025,10 +1018,12 @@ export default function Sessions() {
if (activeModifiers.ctrl) {
finalKey = String.fromCharCode(key.charCodeAt(0) & 0x1f);
} else if (activeModifiers.alt) {
finalKey = `\x1b${key}`;
finalKey = `\x1b${activeModifiers.shift ? key.toUpperCase() : key}`;
} else {
finalKey = key;
dictationSentRef.current = hiddenInputValue + key;
finalKey = activeModifiers.shift
? key.toUpperCase()
: key;
dictationSentRef.current = hiddenInputValue + finalKey;
}
}
}
Expand Down
31 changes: 19 additions & 12 deletions app/tabs/sessions/terminal/keyboard/CustomKeyboard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from "react";
import React, { useState } from "react";
import { View, ScrollView, Text } from "react-native";
import * as Clipboard from "expo-clipboard";
import { TerminalHandle } from "../Terminal";
import KeyboardKey from "./KeyboardKey";
import { useKeyboardCustomization } from "@/app/contexts/KeyboardCustomizationContext";
import { KeyConfig } from "@/types/keyboard";
import { BORDER_COLORS, SPACING } from "@/app/constants/designTokens";
import { BORDER_COLORS } from "@/app/constants/designTokens";

interface CustomKeyboardProps {
terminalRef: React.RefObject<TerminalHandle | null>;
Expand All @@ -17,10 +17,11 @@ interface CustomKeyboardProps {
export default function CustomKeyboard({
terminalRef,
isVisible,
keyboardHeight,
keyboardHeight: _keyboardHeight,
isKeyboardIntentionallyHidden = false,
}: CustomKeyboardProps) {
const { config } = useKeyboardCustomization();
const [shiftPressed, setShiftPressed] = useState(false);

if (!isVisible) return null;

Expand Down Expand Up @@ -50,7 +51,13 @@ export default function CustomKeyboard({
case "tab":
case "complete":
case "comp":
sendKey("\t");
sendKey(shiftPressed ? "\x1b[Z" : "\t");
break;
case "shiftTab":
sendKey("\x1b[Z");
break;
case "shift":
setShiftPressed((current) => !current);
break;
case "arrowUp":
case "history":
Expand Down Expand Up @@ -98,7 +105,7 @@ export default function CustomKeyboard({
if (clipboardContent) {
sendKey(clipboardContent);
}
} catch (error) {}
} catch {}
};

const { rows } = config.fullKeyboard;
Expand Down Expand Up @@ -128,8 +135,6 @@ export default function CustomKeyboard({
return baseStyle;
};

const safeKeyboardHeight = Math.max(200, Math.min(keyboardHeight, 500));

return (
<View className="h-full bg-dark-bg-darkest" pointerEvents="box-none">
<ScrollView
Expand All @@ -143,14 +148,14 @@ export default function CustomKeyboard({
<View key={row.id}>
{row.label && (
<View className="mb-1 mt-1">
<Text className="text-[11px] text-gray-500 font-semibold uppercase tracking-wide">
<Text className="text-[11px] font-semibold uppercase tracking-wide text-gray-500">
{row.label}
</Text>
</View>
)}

<View
className={`flex-row items-center mb-0 ${
className={`mb-0 flex-row items-center ${
row.category === "number" ? "flex-nowrap" : "flex-wrap"
} ${compactMode ? "-mb-0.5" : ""}`}
style={{ gap: getKeyGap() }}
Expand All @@ -161,6 +166,8 @@ export default function CustomKeyboard({
label={key.label}
onPress={() => handleKeyPress(key)}
style={getKeyStyle(key)}
isModifier={key.isModifier || key.id === "shift"}
isActive={key.id === "shift" && shiftPressed}
keySize={config.settings.keySize}
hapticFeedback={config.settings.hapticFeedback}
/>
Expand All @@ -169,7 +176,7 @@ export default function CustomKeyboard({

{rowIndex < visibleRows.length - 1 && (
<View
className="h-px mx-0"
className="mx-0 h-px"
style={{
backgroundColor: BORDER_COLORS.SEPARATOR,
marginVertical: compactMode ? 4 : 8,
Expand All @@ -180,8 +187,8 @@ export default function CustomKeyboard({
))}

{config.settings.showHints && !isKeyboardIntentionallyHidden && (
<View className="px-2 pt-2 pb-1 items-center">
<Text className="text-[10px] text-gray-600 italic">
<View className="items-center px-2 pb-1 pt-2">
<Text className="text-[10px] italic text-gray-600">
Customize in Settings
</Text>
</View>
Expand Down
33 changes: 31 additions & 2 deletions app/tabs/sessions/terminal/keyboard/KeyDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
KeyConfig,
KeyboardRow,
PresetDefinition,
TopBarConfig,
FullKeyboardConfig,
Expand Down Expand Up @@ -37,6 +36,14 @@ export const ALL_KEYS: Record<string, KeyConfig> = {
isModifier: true,
description: "Alt modifier (toggle)",
},
shift: {
id: "shift",
label: "Shift",
value: "",
category: "modifier",
isModifier: true,
description: "Shift modifier (toggle)",
},

arrowUp: {
id: "arrowUp",
Expand Down Expand Up @@ -465,6 +472,13 @@ export const ALL_KEYS: Record<string, KeyConfig> = {
category: "shortcut",
description: "Alt+D (delete word)",
},
shiftTab: {
id: "shiftTab",
label: "Shift+Tab",
value: "\x1b[Z",
category: "shortcut",
description: "Shift+Tab (reverse tab)",
},

paste: {
id: "paste",
Expand Down Expand Up @@ -496,6 +510,7 @@ const defaultTopBar: TopBarConfig = {
ALL_KEYS.tab,
ALL_KEYS.ctrl,
ALL_KEYS.alt,
ALL_KEYS.shift,
ALL_KEYS.arrowUp,
ALL_KEYS.arrowDown,
ALL_KEYS.arrowLeft,
Expand Down Expand Up @@ -654,6 +669,7 @@ const defaultFullKeyboard: FullKeyboardConfig = {
ALL_KEYS.ctrlR,
ALL_KEYS.ctrlY,
ALL_KEYS.altF,
ALL_KEYS.shiftTab,
],
},
],
Expand All @@ -666,6 +682,7 @@ const minimalTopBar: TopBarConfig = {
ALL_KEYS.tab,
ALL_KEYS.ctrl,
ALL_KEYS.alt,
ALL_KEYS.shift,
ALL_KEYS.arrowUp,
ALL_KEYS.arrowDown,
ALL_KEYS.arrowLeft,
Expand Down Expand Up @@ -718,7 +735,13 @@ const minimalFullKeyboard: FullKeyboardConfig = {
category: "shortcut",
label: "Shortcuts",
visible: true,
keys: [ALL_KEYS.ctrlC, ALL_KEYS.ctrlD, ALL_KEYS.ctrlL, ALL_KEYS.ctrlZ],
keys: [
ALL_KEYS.ctrlC,
ALL_KEYS.ctrlD,
ALL_KEYS.ctrlL,
ALL_KEYS.ctrlZ,
ALL_KEYS.shiftTab,
],
},
],
};
Expand All @@ -729,6 +752,7 @@ const developerTopBar: TopBarConfig = {
ALL_KEYS.tab,
ALL_KEYS.ctrl,
ALL_KEYS.alt,
ALL_KEYS.shift,
ALL_KEYS.arrowUp,
ALL_KEYS.arrowDown,
ALL_KEYS.arrowLeft,
Expand Down Expand Up @@ -841,6 +865,7 @@ const developerFullKeyboard: FullKeyboardConfig = {
ALL_KEYS.ctrlU,
ALL_KEYS.ctrlR,
ALL_KEYS.ctrlW,
ALL_KEYS.shiftTab,
],
},
],
Expand All @@ -853,6 +878,7 @@ const sysadminTopBar: TopBarConfig = {
ALL_KEYS.tab,
ALL_KEYS.ctrl,
ALL_KEYS.alt,
ALL_KEYS.shift,
ALL_KEYS.arrowUp,
ALL_KEYS.arrowDown,
ALL_KEYS.arrowLeft,
Expand Down Expand Up @@ -940,6 +966,7 @@ const sysadminFullKeyboard: FullKeyboardConfig = {
ALL_KEYS.ctrlL,
ALL_KEYS.ctrlR,
ALL_KEYS.ctrlU,
ALL_KEYS.shiftTab,
],
},
],
Expand All @@ -952,6 +979,7 @@ const compactTopBar: TopBarConfig = {
ALL_KEYS.tab,
ALL_KEYS.ctrl,
ALL_KEYS.alt,
ALL_KEYS.shift,
ALL_KEYS.arrowUp,
ALL_KEYS.arrowDown,
ALL_KEYS.arrowLeft,
Expand Down Expand Up @@ -1081,6 +1109,7 @@ const compactFullKeyboard: FullKeyboardConfig = {
ALL_KEYS.ctrlU,
ALL_KEYS.ctrlW,
ALL_KEYS.ctrlR,
ALL_KEYS.shiftTab,
],
},
],
Expand Down
Loading