feat: open editor in zellij pane - #240
Draft
souhoc wants to merge 1 commit into
Draft
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Owner
|
Hi, Thank you for this PR and for your interest in the project! Thanks as well for bringing up this use case. I don't think adding specific support for Zellij is the best long-term solution. I think it would be better to find a cleaner and more general way to support Open in Editor when running inside terminal multiplexers, so we don't have to add specific handling for each multiplexer in the future. I'll look into this and work on a more general approach, and I'll keep you posted. Thanks again for the contribution and for raising this! |
RivoLink
marked this pull request as draft
August 10, 2026 16:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Inside a zellij session,
Ctrl+Enow opens the editor in a zellij pane placed over leaf's own pane (zellij action edit --in-place --line-number <line> <file>) instead of a new tab of the host terminal.is_zellij()— detects theZELLIJenv var, alongside the existingis_wsl().zellij_edit_command()— builds that command as aRunAndCheckstrategy.try_new_tab_command()gainsline: usizeandzellij: bool; whenzellijis set it short-circuits ahead of the emulator match, so zellij wins over kitty / gnome-terminal / Windows Terminal / iTerm2 / Terminal.app.open_in_editor()forwards the visible source line (app.source_line_at(app.scroll())).Why
detect_terminal_emulator()reads the host terminal's environment (TERM_PROGRAM,KITTY_PID, …), and those variables are still set inside a zellij session. So leaf opened its editor tab in the host terminal — outside the multiplexer, in a window the user had deliberately left behind.Two deliberate choices:
bool, not a newTerminalEmulatorvariant.detect_terminal_emulator()also feedsselection_modifier_label(), and the host terminal still owns text selection under zellij. A new variant would have flipped the help-popup hint fromoption+dragtoshift+dragon iTerm2. Passing the flag the waywslalready is keeps that hint correct and keeps the branch unit-testable.RunAndCheck, notSpawnAndAssume. The zellij CLI exits non-zero when it cannot reach the session, so leaf falls through toNeedsSameTerminaland edits inline rather than appearing to do nothing.Alternative:
zellij runinstead ofzellij action editHappy to ship this instead if you prefer it — it is a smaller patch than the one above, and I have no strong preference.
zellij action editdelegates to zellij's own editor, which is where every trade-off below comes from.zellij runtakes a command, so leaf's configured editor can be launched directly:editorsetting and its{$line}/{$path}placeholders apply on this path like they do everywhere else — the string passed totry_new_tab_command()is already expanded.line: usizeis then no longer needed at all: it disappears fromzellij_edit_command(),try_new_tab_command()andopen_in_editor(), along with the secondsource_line_at()call inruntime/mouse.rs.--namecan reuseformat_editor_tab_title(), sotab-title-lengthapplies here too. The current patch silently ignores it.EditorFlash::Openedbecomes truthful, since the launched binary is the configured one.The reason it is not the default here: it changes which editor opens for anyone who has set zellij's
scrollback_editor. That felt like the maintainers' call rather than mine. Flags verified against zellij 0.44.0 (run -i/--in-place,-n/--name,-c/--close-on-exit).Trade-offs of the approach in this PR
zellij action edituses zellij's own editor (scrollback_editor, else$EDITOR), so theeditorsetting and its{$line}/{$path}placeholders do not apply on this path. Forwarding--line-numberis what keeps line positioning working there without a placeholder.code,zed, …) are untouched — they never went through the tab path.EditorFlash::Openedstill reports leaf's configured editor name, which may differ from what zellij launched. With--in-placeleaf's pane is suspended while editing, so the flash is effectively never seen; left alone rather than wideningEditorResultfor an invisible string.How tested
cargo test— 417 passed, including 4 new tests: the in-place command shape, zellij winning over each host emulator, the visible line being forwarded, and line0clamped to1.cargo clippy --all-targets --all-features -- -D warnings— clean.cargo fmt --all -- --check— clean.cargo build --release— ok.Open in Editorsection).Ctrl+Eopens the editor in place of leaf's pane as described.🤖 Generated with Claude Code