From 900b127a047e3d8ba9b94e108dc73b17174ae2c7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 20 Dec 2023 22:12:04 -0800 Subject: [PATCH] core: cursor click to move can be disabled --- README.md | 1 + src/Surface.zig | 5 +++++ src/config/Config.zig | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 68da271fa..28ff78e8d 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ The currently supported shell integration features in Ghostty: - The cursor at the prompt is turned into a bar. - The `jump_to_prompt` keybinding can be used to scroll the terminal window forward and back through prompts. +- Alt+click (option+click on macOS) to move the cursor at the prompt. #### Shell Integration Installation and Verification diff --git a/src/Surface.zig b/src/Surface.zig index 1a4959c17..40f3b3f5a 100644 --- a/src/Surface.zig +++ b/src/Surface.zig @@ -182,6 +182,7 @@ const DerivedConfig = struct { clipboard_paste_bracketed_safe: bool, copy_on_select: configpkg.CopyOnSelect, confirm_close_surface: bool, + cursor_click_to_move: bool, desktop_notifications: bool, mouse_interval: u64, mouse_hide_while_typing: bool, @@ -235,6 +236,7 @@ const DerivedConfig = struct { .clipboard_paste_bracketed_safe = config.@"clipboard-paste-bracketed-safe", .copy_on_select = config.@"copy-on-select", .confirm_close_surface = config.@"confirm-close-surface", + .cursor_click_to_move = config.@"cursor-click-to-move", .desktop_notifications = config.@"desktop-notifications", .mouse_interval = config.@"click-repeat-interval" * 1_000_000, // 500ms .mouse_hide_while_typing = config.@"mouse-hide-while-typing", @@ -2094,6 +2096,9 @@ pub fn mouseButtonCallback( /// screen point if possible. This works by converting the path to the /// given point into a series of arrow key inputs. fn clickMoveCursor(self: *Surface, to: terminal.point.ScreenPoint) !void { + // If click-to-move is disabled then we're done. + if (!self.config.cursor_click_to_move) return; + const t = &self.io.terminal; // Click to move cursor only works on the primary screen where prompts diff --git a/src/config/Config.zig b/src/config/Config.zig index 2ca1c4a18..0a019b70d 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -264,6 +264,21 @@ palette: Palette = .{}, /// will be chosen. @"cursor-text": ?Color = null, +/// Enables the ability to move the cursor at prompts by using alt+click +/// on Linux and option+click on macOS. +/// +/// This feature requires shell integration (specifically prompt marking +/// via OSC 133) and only works in primary screen mode. Alternate screen +/// applications like vim usually have their own version of this feature +/// but this configuration doesn't control that. +/// +/// It should be noted that this feature works by translating your desired +/// position into a series of synthetic arrow key movements, so some weird +/// behavior around edge cases are to be expected. This is unfortunately +/// how this feature is implemented across terminals because there isn't +/// any other way to implement it. +@"cursor-click-to-move": bool = true, + /// Hide the mouse immediately when typing. The mouse becomes visible /// again when the mouse is used. The mouse is only hidden if the mouse /// cursor is over the active terminal surface.