[PR #12728] fix: editor empty content and exit code handling #14341

Open
opened 2026-02-16 18:19:08 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12728

State: open
Merged: No


What does this PR do?

Prior to this commit, the editor had two issues:

  1. Empty content was discarded: When a user saved an empty file in the external editor (e.g., clearing all text), the check if (!content) would treat empty strings as falsy and reject valid empty content.
  2. Editor cancellation wasn't detected: The editor process exit code was ignored, so even if the user cancelled/quitted the editor without saving (non-zero exit), the file content would still be returned as if it were saved.

This commit fixes both issues by checking for undefined specifically instead of falsy values, and by checking the editor's exit code to properly distinguish between saved content and cancelled edits.

How did you verify your code works?

Test Case 1: Empty content handling

  1. Type some text in the chat input box
  2. Press Ctrl+X E to open the external editor
  3. Delete all text in the editor
  4. Save and exit (:wq in vim)
  5. Expected: The chat input should now be empty (previously it would keep the original text)

Test Case 2: Editor cancellation

  1. Type some text in the chat input box
  2. Press Ctrl+X E to open the external editor
  3. Make some changes in the editor
  4. Exit without saving (:q! in vim, or just quit without saving)
  5. Expected: The chat input should remain unchanged with the original text (previously, it would apply the changes anyway)

Fixes #12729

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12728 **State:** open **Merged:** No --- ### What does this PR do? Prior to this commit, the editor had two issues: 1. Empty content was discarded: When a user saved an empty file in the external editor (e.g., clearing all text), the check if (!content) would treat empty strings as falsy and reject valid empty content. 2. Editor cancellation wasn't detected: The editor process exit code was ignored, so even if the user cancelled/quitted the editor without saving (non-zero exit), the file content would still be returned as if it were saved. This commit fixes both issues by checking for undefined specifically instead of falsy values, and by checking the editor's exit code to properly distinguish between saved content and cancelled edits. ### How did you verify your code works? Test Case 1: Empty content handling 1. Type some text in the chat input box 2. Press Ctrl+X E to open the external editor 3. Delete all text in the editor 4. Save and exit (:wq in vim) 5. Expected: The chat input should now be empty (previously it would keep the original text) Test Case 2: Editor cancellation 1. Type some text in the chat input box 2. Press Ctrl+X E to open the external editor 3. Make some changes in the editor 4. Exit without saving (:q! in vim, or just quit without saving) 5. Expected: The chat input should remain unchanged with the original text (previously, it would apply the changes anyway) Fixes #12729
yindo added the pull-request label 2026-02-16 18:19:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14341