Skip to content

Commit c47fbeb

Browse files
committed
fix(api): suppress tmux right-click drag menu
1 parent 03ec1d8 commit c47fbeb

2 files changed

Lines changed: 36 additions & 8 deletions

File tree

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,25 +765,40 @@ 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> = [
768+
const tmuxRightClickForwardPredicate =
769+
"#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}"
770+
const tmuxRightClickPaneBindings: ReadonlyArray<string> = [
771+
"MouseDown3Pane",
772+
"MouseDrag3Pane",
773+
"MouseDragEnd3Pane",
774+
"MouseUp3Pane",
775+
"M-MouseDown3Pane",
776+
"M-MouseDrag3Pane",
777+
"M-MouseDragEnd3Pane",
778+
"M-MouseUp3Pane"
779+
]
780+
const tmuxRightClickSuppressBindings: ReadonlyArray<string> = [
770781
"MouseDown3Status",
771782
"MouseDown3StatusLeft",
783+
"MouseDown3StatusRight",
784+
"MouseDown3Border",
772785
"M-MouseDown3Status",
773-
"M-MouseDown3StatusLeft"
786+
"M-MouseDown3StatusLeft",
787+
"M-MouseDown3StatusRight",
788+
"M-MouseDown3Border"
774789
]
775790

776791
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")
792+
`tmux bind-key -T root ${binding} if-shell -F -t = ${shellQuote(tmuxRightClickForwardPredicate)} ${
793+
shellQuote("select-pane -t = ; send-keys -M")
779794
} >/dev/null 2>&1 || true`
780795

781-
const renderTmuxStatusRightClickUnbind = (binding: string): string =>
796+
const renderTmuxRightClickSuppressBinding = (binding: string): string =>
782797
`tmux unbind-key -T root ${binding} >/dev/null 2>&1 || true`
783798

784799
const renderTmuxRightClickBindingCommands = (): ReadonlyArray<string> => [
785800
...tmuxRightClickPaneBindings.map(renderTmuxPaneRightClickBinding),
786-
...tmuxRightClickStatusBindings.map(renderTmuxStatusRightClickUnbind)
801+
...tmuxRightClickSuppressBindings.map(renderTmuxRightClickSuppressBinding)
787802
]
788803

789804
const writeBufferToProjectContainer = (

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,26 @@ describe("terminal sessions service", () => {
255255
expect(command).toContain("history-limit 50000")
256256
expect(command).toContain("mouse on")
257257
expect(command).toContain("bind-key -T root MouseDown3Pane")
258+
expect(command).toContain("bind-key -T root MouseDrag3Pane")
259+
expect(command).toContain("bind-key -T root MouseDragEnd3Pane")
260+
expect(command).toContain("bind-key -T root MouseUp3Pane")
258261
expect(command).toContain("bind-key -T root M-MouseDown3Pane")
259-
expect(command).toContain("#{mouse_any_flag}")
262+
expect(command).toContain("bind-key -T root M-MouseDrag3Pane")
263+
expect(command).toContain("bind-key -T root M-MouseDragEnd3Pane")
264+
expect(command).toContain("bind-key -T root M-MouseUp3Pane")
265+
expect(command).toContain("#{||:#{mouse_any_flag}")
266+
expect(command).toContain("#{pane_in_mode}")
267+
expect(command).toContain("#{pane_mode}")
268+
expect(command).toContain("select-pane -t = ; send-keys -M")
260269
expect(command).toContain("send-keys -M")
261270
expect(command).toContain("unbind-key -T root MouseDown3Status")
262271
expect(command).toContain("unbind-key -T root MouseDown3StatusLeft")
272+
expect(command).toContain("unbind-key -T root MouseDown3StatusRight")
273+
expect(command).toContain("unbind-key -T root MouseDown3Border")
263274
expect(command).toContain("unbind-key -T root M-MouseDown3Status")
264275
expect(command).toContain("unbind-key -T root M-MouseDown3StatusLeft")
276+
expect(command).toContain("unbind-key -T root M-MouseDown3StatusRight")
277+
expect(command).toContain("unbind-key -T root M-MouseDown3Border")
265278
expect(command).not.toContain("display-menu")
266279
expect(command).toContain("tmux attach-session -t")
267280
expect(command).toContain("docker-git-session-1")

0 commit comments

Comments
 (0)