Skip to content

terminal_view: Fix terminal opening in root directory when editing single file corktree#42953

Merged
Veykril merged 1 commit intozed-industries:mainfrom
canack:fix-terminal-single-file-directory
Nov 18, 2025
Merged

terminal_view: Fix terminal opening in root directory when editing single file corktree#42953
Veykril merged 1 commit intozed-industries:mainfrom
canack:fix-terminal-single-file-directory

Conversation

@canack
Copy link
Contributor

@canack canack commented Nov 18, 2025

Fixes #42945

Problem

When opening a single file via command line (e.g., zed ~/Downloads/file.txt), the terminal panel was opening in the root directory (/) instead of the file's directory.

Root Cause

The code only checked for active project directory, which returns None when a single file is opened. Additionally, file worktrees weren't handling parent directory lookup.

Solution

Added fallback logic to use the first project directory when there's no active entry, and made file worktrees return their parent directory instead of None.

Testing

  • All existing tests pass
  • Added test coverage for file worktree scenarios
  • Manually tested with zed ~/Downloads/file.txt - terminal now opens in correct directory

This improves the user experience for users who frequently open single files from the command line.

Release Notes

  • Fixed terminal opening in root directory when editing single files from the command line

Fixes zed-industries#42945

When opening a single file via command line, the terminal was opening
in root directory instead of the file's directory.

This fix adds fallback logic and makes first_project_directory return
the parent directory for file worktrees.
@cla-bot
Copy link

cla-bot bot commented Nov 18, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @canack on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-industries-bot
Copy link
Contributor

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against 14fe42e

@canack
Copy link
Contributor Author

canack commented Nov 18, 2025

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Nov 18, 2025
@cla-bot
Copy link

cla-bot bot commented Nov 18, 2025

The cla-bot has been summoned, and re-checked this pull request!

@Veykril Veykril self-assigned this Nov 18, 2025
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

Thanks!

@Veykril Veykril changed the title Fix terminal opens in root directory when editing single file terminal_view: Fix terminal opening in root directory when editing single file corktree Nov 18, 2025
@Veykril Veykril merged commit f17d2c9 into zed-industries:main Nov 18, 2025
27 checks passed
@canack canack deleted the fix-terminal-single-file-directory branch November 18, 2025 12:44
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
…ngle file corktree (zed-industries#42953)

Fixes zed-industries#42945

## Problem
When opening a single file via command line (e.g., `zed
~/Downloads/file.txt`), the terminal panel was opening in the root
directory (/) instead of the file's directory.

## Root Cause
The code only checked for active project directory, which returns None
when a single file is opened. Additionally, file worktrees weren't
handling parent directory lookup.

## Solution
Added fallback logic to use the first project directory when there's no
active entry, and made file worktrees return their parent directory
instead of None.

## Testing
- All existing tests pass
- Added test coverage for file worktree scenarios
- Manually tested with `zed ~/Downloads/file.txt` - terminal now opens
in correct directory

This improves the user experience for users who frequently open single
files from the command line.

## Release Notes

- Fixed terminal opening in root directory when editing single files
from the command line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal opens in / when editing a single file

3 participants