From c97c0858bedf7f21af2175e9ddd1be38aa3bfe4b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 30 Oct 2024 20:44:47 -0400 Subject: [PATCH] macos: rectangle select only requires option + drag Fixes #2537 This matches Terminal.app. iTerm2 requires cmd+option (our old behavior). Kitty doesn't seem to support rectangle select or I couldn't figure out how to make it work. WezTerm matches Terminal.app too. Outside of terminal emulators, this is also the rectangular select binding for neovim. --- .../Features/Terminal/BaseTerminalController.swift | 2 +- src/Surface.zig | 4 ++-- src/surface_mouse.zig | 13 +++++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/macos/Sources/Features/Terminal/BaseTerminalController.swift b/macos/Sources/Features/Terminal/BaseTerminalController.swift index 8acda4ed1..000d72418 100644 --- a/macos/Sources/Features/Terminal/BaseTerminalController.swift +++ b/macos/Sources/Features/Terminal/BaseTerminalController.swift @@ -146,7 +146,7 @@ class BaseTerminalController: NSWindowController, } // MARK: Notifications - + @objc private func didChangeScreenParametersNotification(_ notification: Notification) { // If we have a window that is visible and it is outside the bounds of the // screen then we clamp it back to within the screen. diff --git a/src/Surface.zig b/src/Surface.zig index 5c06ed985..9521e34dc 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -3468,7 +3468,7 @@ fn dragLeftClickSingle( try self.setSelection(if (selected) terminal.Selection.init( drag_pin, drag_pin, - self.mouse.mods.ctrlOrSuper() and self.mouse.mods.alt, + SurfaceMouse.isRectangleSelectState(self.mouse.mods), ) else null); return; @@ -3503,7 +3503,7 @@ fn dragLeftClickSingle( try self.setSelection(terminal.Selection.init( start, drag_pin, - self.mouse.mods.ctrlOrSuper() and self.mouse.mods.alt, + SurfaceMouse.isRectangleSelectState(self.mouse.mods), )); return; } diff --git a/src/surface_mouse.zig b/src/surface_mouse.zig index 2ba88540c..cc1643a88 100644 --- a/src/surface_mouse.zig +++ b/src/surface_mouse.zig @@ -113,14 +113,19 @@ fn eligibleMouseShapeKeyEvent(physical_key: input.Key) bool { physical_key.leftOrRightAlt(); } -fn isRectangleSelectState(mods: input.Mods) bool { - return mods.ctrlOrSuper() and mods.alt; -} - fn isMouseModeOverrideState(mods: input.Mods) bool { return mods.shift; } +/// Returns true if our modifiers put us in a state where dragging +/// should cause a rectangle select. +pub fn isRectangleSelectState(mods: input.Mods) bool { + return if (comptime builtin.target.isDarwin()) + mods.alt + else + mods.ctrlOrSuper() and mods.alt; +} + test "keyToMouseShape" { const testing = std.testing;