terminal: Resolve path hyperlinks using per-line cwd (#52454)

## Context

When cmd/ctrl-clicking a relative path in the terminal, Zed was
resolving it against the *current* working directory at click time, not
the directory that was active when the line was printed. So if you run
command `cd folder1` after running command `ls`, clicking `test.txt` in
the old `ls` output would open `ROOT/test.txt` instead of
`ROOT/folder1/test.txt`.

The approach is similar to the VSCode approach for hyperlinks in the
terminal

**Video below of the test on VSCode:**

[Screencast from 2026-03-25
23-28-26.webm](https://github.com/user-attachments/assets/d1c3b163-7b18-43db-9981-71c1cb09a801)

**Video below of the test on Zed after the fix:**

[Screencast from 2026-03-25
23-31-49.webm](https://github.com/user-attachments/assets/fc23da34-dd16-4cce-afed-53f681762152)

Closes #52325

## How to Review

Two files changed — read in this order:

1. **`crates/terminal/src/pty_info.rs`** Bug fix:
`emit_title_changed_if_changed` was comparing cwd with itself because
`load()` writes to `self.current` *before* the comparison. Fixed by
capturing `prev_cwd`/`prev_name` before calling `load()`. Also extended
the background task to return the new cwd when it changes, so the
foreground task can call `terminal.record_cwd_change(cwd)`.

2. **`crates/terminal/src/terminal.rs`** 
- `cwd_history: Vec<(i32, PathBuf)>` field on `Terminal`, seeded with
`(i32::MIN, initial_cwd)` for PTY terminals so all pre-history lines
resolve correctly.
- `record_cwd_change` called when the PTY cwd changes; records the
current scrollback position alongside the new path.
- `cwd_at_line` given a scrollback line, binary-searches the history to
find the most recent cwd active at or before that line.
- `process_hyperlink` updated to use `cwd_at_line` for both plain paths
and `file://` URLs.

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed terminal path hyperlinks resolving against the current working
directory instead of the one active when the line was printed

---------

Co-authored-by: Lukas Wirth <lukas@zed.dev>
Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
184e124bbaSaber Oueslati committed on 8/4/2026, 9:27:46 AM· committed by GitHubparente717010
3 files changedLine totals unavailable