Skip to content

Commit 03ec1d8

Browse files
committed
fix(api): disable tmux right-click menu
1 parent bc06d7f commit 03ec1d8

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

packages/api/src/services/terminal-sessions.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,27 @@ const writePtyInput = (pty: PtyBridge | null, data: string): void => {
765765

766766
const shellQuote = (value: string): string => `'${value.replace(/'/gu, "'\\''")}'`
767767

768+
const tmuxRightClickPaneBindings: ReadonlyArray<string> = ["MouseDown3Pane", "M-MouseDown3Pane"]
769+
const tmuxRightClickStatusBindings: ReadonlyArray<string> = [
770+
"MouseDown3Status",
771+
"MouseDown3StatusLeft",
772+
"M-MouseDown3Status",
773+
"M-MouseDown3StatusLeft"
774+
]
775+
776+
const renderTmuxPaneRightClickBinding = (binding: string): string =>
777+
`tmux bind-key -T root ${binding} if-shell -F -t = ${shellQuote("#{mouse_any_flag}")} ${
778+
shellQuote("send-keys -M")
779+
} >/dev/null 2>&1 || true`
780+
781+
const renderTmuxStatusRightClickUnbind = (binding: string): string =>
782+
`tmux unbind-key -T root ${binding} >/dev/null 2>&1 || true`
783+
784+
const renderTmuxRightClickBindingCommands = (): ReadonlyArray<string> => [
785+
...tmuxRightClickPaneBindings.map(renderTmuxPaneRightClickBinding),
786+
...tmuxRightClickStatusBindings.map(renderTmuxStatusRightClickUnbind)
787+
]
788+
768789
const writeBufferToProjectContainer = (
769790
containerName: string,
770791
containerPath: string,
@@ -982,6 +1003,7 @@ export const renderTmuxAttachCommand = (
9821003
`tmux set-option -t ${shellQuote(args.tmuxName)} status off >/dev/null 2>&1 || true`,
9831004
`tmux set-option -t ${shellQuote(args.tmuxName)} history-limit 50000 >/dev/null 2>&1 || true`,
9841005
`tmux set-option -t ${shellQuote(args.tmuxName)} mouse on >/dev/null 2>&1 || true`,
1006+
...renderTmuxRightClickBindingCommands(),
9851007
`exec tmux attach-session -t ${shellQuote(args.tmuxName)}`
9861008
].join("; ")
9871009
return `bash --noprofile --norc -lc ${shellQuote(script)}`

packages/api/tests/terminal-sessions.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ describe("terminal sessions service", () => {
254254
expect(command).toContain("status off")
255255
expect(command).toContain("history-limit 50000")
256256
expect(command).toContain("mouse on")
257+
expect(command).toContain("bind-key -T root MouseDown3Pane")
258+
expect(command).toContain("bind-key -T root M-MouseDown3Pane")
259+
expect(command).toContain("#{mouse_any_flag}")
260+
expect(command).toContain("send-keys -M")
261+
expect(command).toContain("unbind-key -T root MouseDown3Status")
262+
expect(command).toContain("unbind-key -T root MouseDown3StatusLeft")
263+
expect(command).toContain("unbind-key -T root M-MouseDown3Status")
264+
expect(command).toContain("unbind-key -T root M-MouseDown3StatusLeft")
265+
expect(command).not.toContain("display-menu")
257266
expect(command).toContain("tmux attach-session -t")
258267
expect(command).toContain("docker-git-session-1")
259268
expect(command).toContain("/home/dev/project with spaces")
@@ -264,6 +273,7 @@ describe("terminal sessions service", () => {
264273
const statusOffIndex = command.indexOf("status off")
265274
const sessionHistoryLimitIndex = command.lastIndexOf("history-limit 50000")
266275
const mouseOnIndex = command.indexOf("mouse on")
276+
const rightClickBindingIndex = command.indexOf("MouseDown3Pane")
267277
const attachSessionIndex = command.indexOf("tmux attach-session -t")
268278

269279
expect(startServerIndex).toBeGreaterThanOrEqual(0)
@@ -272,13 +282,15 @@ describe("terminal sessions service", () => {
272282
expect(statusOffIndex).toBeGreaterThanOrEqual(0)
273283
expect(sessionHistoryLimitIndex).toBeGreaterThanOrEqual(0)
274284
expect(mouseOnIndex).toBeGreaterThanOrEqual(0)
285+
expect(rightClickBindingIndex).toBeGreaterThan(mouseOnIndex)
275286
expect(attachSessionIndex).toBeGreaterThanOrEqual(0)
276287
expect(startServerIndex).toBeLessThan(globalHistoryLimitIndex)
277288
expect(globalHistoryLimitIndex).toBeLessThan(newSessionIndex)
278289
expect(newSessionIndex).toBeLessThan(statusOffIndex)
279290
expect(statusOffIndex).toBeLessThan(sessionHistoryLimitIndex)
280291
expect(sessionHistoryLimitIndex).toBeLessThan(mouseOnIndex)
281-
expect(mouseOnIndex).toBeLessThan(attachSessionIndex)
292+
expect(mouseOnIndex).toBeLessThan(rightClickBindingIndex)
293+
expect(rightClickBindingIndex).toBeLessThan(attachSessionIndex)
282294
})
283295

284296
it("fails before creating a durable session when tmux is unavailable", async () => {

0 commit comments

Comments
 (0)