Skip to content

Commit b203489

Browse files
committed
fix: allow Option/Alt composed characters in terminals on macOS
1 parent f08c53c commit b203489

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎apps/dokploy/components/dashboard/docker/terminal/docker-terminal.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "@xterm/xterm/css/xterm.css";
55
import { AttachAddon } from "@xterm/addon-attach";
66
import { useTheme } from "next-themes";
77
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
8+
import { fixMacOsAltKeys } from "@/lib/terminal-keyboard";
89

910
interface Props {
1011
id: string;
@@ -45,6 +46,7 @@ export const DockerTerminal: React.FC<Props> = ({
4546
const ws = new WebSocket(wsUrl);
4647

4748
const addonAttach = new AttachAddon(ws);
49+
fixMacOsAltKeys(term);
4850
// @ts-ignore
4951
term.open(termRef.current);
5052
// @ts-ignore

‎apps/dokploy/components/dashboard/settings/web-server/terminal.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "@xterm/xterm/css/xterm.css";
66
import { AttachAddon } from "@xterm/addon-attach";
77
import { ClipboardAddon } from "@xterm/addon-clipboard";
88
import { useTheme } from "next-themes";
9+
import { fixMacOsAltKeys } from "@/lib/terminal-keyboard";
910
import { getLocalServerData } from "./local-server-config";
1011

1112
interface Props {
@@ -58,6 +59,7 @@ export const Terminal: React.FC<Props> = ({ id, serverId }) => {
5859
const addonAttach = new AttachAddon(ws);
5960
const clipboardAddon = new ClipboardAddon();
6061
term.loadAddon(clipboardAddon);
62+
fixMacOsAltKeys(term);
6163

6264
// @ts-ignore
6365
term.open(termRef.current);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Terminal } from "@xterm/xterm";
2+
3+
// xterm's platform detection mistakes the bundled Next.js `process` polyfill
4+
// for Node.js, so it never treats Option/Alt as third-level shift on macOS and
5+
// swallows composed characters like Option+L (@ on German layouts).
6+
// https://github.com/Dokploy/dokploy/issues/4297
7+
export const fixMacOsAltKeys = (term: Terminal) => {
8+
if (!/Mac/.test(navigator.platform)) {
9+
return;
10+
}
11+
term.attachCustomKeyEventHandler((event) => {
12+
if (
13+
event.type === "keydown" &&
14+
event.altKey &&
15+
!event.ctrlKey &&
16+
!event.metaKey &&
17+
event.key.length === 1
18+
) {
19+
event.preventDefault();
20+
term.input(event.key);
21+
return false;
22+
}
23+
return true;
24+
});
25+
};

0 commit comments

Comments
 (0)