Skip to content

Don't move the cursor to the start of the input if clicking on a prompt-only line - #11711

Open
hlcfan wants to merge 7 commits into
ghostty-org:mainfrom
hlcfan:prompt-click-cursor-movement
Open

hlcfan wants to merge 7 commits into
ghostty-org:mainfrom
hlcfan:prompt-click-cursor-movement

Conversation

@hlcfan

@hlcfan hlcfan commented Mar 21, 2026 •

Copy link
Copy Markdown

Fix #11462

Bug

When user clicks on a purely prompt line without input area, it moves the cursor
to the start of the input. For example, I use starship prompt, it shows a whole
line for the prompt, e.g.

{username} {cwd} // prompt line
> ls -lah        // input

When user double clicks on the prompt area to copy text, the cursor shouldn't
move.

Fix

In promptClickLine, when user clicks on a prompt area, it traverses down the
prompt rows. If one of the rows contains input, allows the cursor movement.
Otherwise, if pure prompt line, return zero movement.

AI Usage

I used Antigravity to pinpoint the prompt area clicking logic.

@hlcfan
hlcfan requested a review from a team as a code owner March 21, 2026 01:34

@mitchellh mitchellh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some stylistic Zig stuff here I want to fix but willing to do later.

@hlcfan

hlcfan commented May 6, 2026

Copy link
Copy Markdown
Author

Hi @mitchellh is this PR good to go or pending anything?

@PRIHLOP

PRIHLOP commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Hello.
I re-tested this PR against current main
(683d8db643b95cf229bfb5fe9fab9ae677920343).

Refresh required

The fix is still valid and the full promptClickMove test filter
passes after a small API refresh. Git merges the branch without
textual conflicts, but the result does not compile as-is because
three APIs changed since March.

The required API refresh is limited to these changes in
src/terminal/Screen.zig:

-const cells = row_pin.node.data.getCells(rac.row);
+const cells = row_pin.node.page().getCells(rac.row);

And in both newly added tests:

 const testing = std.testing;
 const alloc = testing.allocator;
+const io = testing.io;

-var s = try init(alloc, .{ .cols = ..., .rows = 5, .max_scrollback = 0 });
+var s = try init(io, alloc, .{ .cols = ..., .rows = 5, .max_scrollback_bytes = 0 });

Verification

I created a local merge of the PR into current main, applied only the three mechanical API adaptations above, and ran:

zig fmt --check src/terminal/Screen.zig
zig build test -j1 -Dtest-filter="promptClickMove"

Both completed successfully (exit 0). This filter includes the two PR regression scenarios and the existing promptClickMove tests:

  • clicking a pure prompt-only row returns zero movement;
  • clicking a wrapped prompt that contains input still moves to the input correctly;
  • existing left/right prompt-click behavior remains green.

Environment:

  • Linux 6.12.100+deb13-amd64, x86_64
  • Debian 13 (trixie) container
  • Zig 0.16.0
  • GTK 4.18.6
  • libadwaita 1.7.6

AI assistance disclosure: I used Hermes Agent(with LLM GPT 5.6 Sol) to inspect the current upstream state, prepare the local refresh, run the test matrix, and draft this report. I reviewed the changes and results.

Guys, could you please help with this PR @mitchellh @hlcfan

@hlcfan

hlcfan commented Aug 26, 2026

Copy link
Copy Markdown
Author

Thanks @PRIHLOP for reporting this. Updated the code according to the API change.

@PRIHLOP

PRIHLOP commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Hello @mitchellh
Could you please approve workflows to complete checks of these changes?

@PRIHLOP

PRIHLOP commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Hello @jcollie
Could you please help with review and approve (second is needed) of these changes?

@hlcfan
hlcfan requested a review from mitchellh August 28, 2026 23:35

@jcollie jcollie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add a test that has a starship-style prompt that looks like the prompt in the issue.

Comment thread src/terminal/Screen.zig Resolved
@jcollie

jcollie commented Oct 30, 2026

Copy link
Copy Markdown
Member

@hlcfan can you rebase instead of merging main?

@hlcfan
hlcfan force-pushed the prompt-click-cursor-movement branch from 688bc26 to 5ad2b6d Compare October 30, 2026 06:25
@hlcfan

hlcfan commented Oct 30, 2026

Copy link
Copy Markdown
Author

@jcollie Done.

@jcollie jcollie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI

@hlcfan

hlcfan commented Nov 3, 2026

Copy link
Copy Markdown
Author

@jcollie @mitchellh is it good to go?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clicking a prompt line with no input shouldn’t move the cursor to the start of the input

4 participants