mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-08 13:05:17 +00:00
Merge pull request #5017 from Dokploy/fix/terminal-mac-option-keys-4297
fix: allow Option/Alt composed characters in terminals on macOS
This commit is contained in:
@@ -5,6 +5,7 @@ import "@xterm/xterm/css/xterm.css";
|
|||||||
import { AttachAddon } from "@xterm/addon-attach";
|
import { AttachAddon } from "@xterm/addon-attach";
|
||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "next-themes";
|
||||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
|
import { fixMacOsAltKeys } from "@/lib/terminal-keyboard";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -45,6 +46,7 @@ export const DockerTerminal: React.FC<Props> = ({
|
|||||||
const ws = new WebSocket(wsUrl);
|
const ws = new WebSocket(wsUrl);
|
||||||
|
|
||||||
const addonAttach = new AttachAddon(ws);
|
const addonAttach = new AttachAddon(ws);
|
||||||
|
fixMacOsAltKeys(term);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
term.open(termRef.current);
|
term.open(termRef.current);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import "@xterm/xterm/css/xterm.css";
|
|||||||
import { AttachAddon } from "@xterm/addon-attach";
|
import { AttachAddon } from "@xterm/addon-attach";
|
||||||
import { ClipboardAddon } from "@xterm/addon-clipboard";
|
import { ClipboardAddon } from "@xterm/addon-clipboard";
|
||||||
import { useTheme } from "next-themes";
|
import { useTheme } from "next-themes";
|
||||||
|
import { fixMacOsAltKeys } from "@/lib/terminal-keyboard";
|
||||||
import { getLocalServerData } from "./local-server-config";
|
import { getLocalServerData } from "./local-server-config";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -58,6 +59,7 @@ export const Terminal: React.FC<Props> = ({ id, serverId }) => {
|
|||||||
const addonAttach = new AttachAddon(ws);
|
const addonAttach = new AttachAddon(ws);
|
||||||
const clipboardAddon = new ClipboardAddon();
|
const clipboardAddon = new ClipboardAddon();
|
||||||
term.loadAddon(clipboardAddon);
|
term.loadAddon(clipboardAddon);
|
||||||
|
fixMacOsAltKeys(term);
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
term.open(termRef.current);
|
term.open(termRef.current);
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import type { Terminal } from "@xterm/xterm";
|
||||||
|
|
||||||
|
// xterm's platform detection mistakes the bundled Next.js `process` polyfill
|
||||||
|
// for Node.js, so it never treats Option/Alt as third-level shift on macOS and
|
||||||
|
// swallows composed characters like Option+L (@ on German layouts).
|
||||||
|
// https://github.com/Dokploy/dokploy/issues/4297
|
||||||
|
export const fixMacOsAltKeys = (term: Terminal) => {
|
||||||
|
if (!/Mac/.test(navigator.platform)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
term.attachCustomKeyEventHandler((event) => {
|
||||||
|
if (
|
||||||
|
event.type === "keydown" &&
|
||||||
|
event.altKey &&
|
||||||
|
!event.ctrlKey &&
|
||||||
|
!event.metaKey &&
|
||||||
|
event.key.length === 1
|
||||||
|
) {
|
||||||
|
event.preventDefault();
|
||||||
|
term.input(event.key);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user