Skip to content

Conversation

@Pnkcaht
Copy link
Contributor

@Pnkcaht Pnkcaht commented Jan 19, 2026

What I did

Adjusted the edit_file TUI rendering logic to skip diff rendering when the tool execution fails.

When an edit fails (e.g. old text not found), the tool does not produce a valid file state. Attempting to render a diff in this scenario led to inconsistent layout calculations and caused the editor scrollbar to go out of bounds.

This change ensures that, on failure, the TUI renders only the formatted error message and avoids invalid diff rendering.

Related issue

Fixes #1366

Notes

  • Skips diff rendering when the edit_file tool returns an error
  • Prevents invalid layout and viewport calculations in the editor
  • Avoids scrollbar overflow after failed edits
  • Keeps existing behavior unchanged for successful edits
  • Purely a TUI rendering fix (no tool or API behavior changes)

Tests

Before

When an edit_file operation failed (e.g. old text not found):

  • The TUI still attempted to render a diff
  • Diff rendering was based on an invalid file state
  • Layout calculations became inconsistent
  • The editor scrollbar could go out of bounds
  • The UI appeared broken after the failed edit

After

When an edit_file operation fails:

  • Diff rendering is skipped entirely
  • Only the formatted error message is shown
  • Layout and viewport calculations remain consistent
  • The editor remains usable and visually stable
  • Successful edits continue to render diffs as before

@Pnkcaht Pnkcaht requested a review from a team as a code owner January 19, 2026 16:42
@Pnkcaht Pnkcaht force-pushed the fix/1366-editor-scroll-after-failed-edit branch from 8e90357 to de6c5e8 Compare January 20, 2026 18:39
@Pnkcaht
Copy link
Contributor Author

Pnkcaht commented Jan 20, 2026

New changes

I adjusted the code to fix the Lint and Test errors on GitHub. A "Resolve conflict" message also appeared in the editfile.go file, which I've already accepted and committed.

@Pnkcaht Pnkcaht force-pushed the fix/1366-editor-scroll-after-failed-edit branch from 2ae905d to d2f5f4e Compare January 20, 2026 19:40
@Pnkcaht
Copy link
Contributor Author

Pnkcaht commented Jan 20, 2026

New changes

I performed the rebase and made the requested change based on reference #1432.
Below is a diagram briefly explaining the old process, which became incorrect after the changes in the aforementioned reference, and the new process that correctly handles the Friendly header. @krissetto

image

@krissetto
Copy link
Contributor

The diff doesn't render on invalid diffs, nice!

There are some small issues with the rendering of tool errors/rejections we need to fix before merging though.

We should:

  • keep some spacing between the tool badge and the error/rejection text;
  • keep the same font styling so it appears consistent with the name of the tool (the "Edit README.md" in the image)
  • make sure to truncate the rejection/error text it if its longer than the available space on the line. Right now it word-wraps off the edge if the terminal is not wide enough
image

@Pnkcaht
Copy link
Contributor Author

Pnkcaht commented Jan 21, 2026

What was changed

@krissetto
This update improves how the edit_file tool behaves and renders output when an edit fails.

Error handling & rendering

  • Skip diff rendering when the tool execution fails, as rendering diffs on failed edits can break layout and scroll calculations.
  • Render tool errors/rejections as a single-line message directly below the tool header.
  • Keep consistent spacing and styling with the tool header (Edit <file>), so errors visually match other tool messages.
  • Truncate long error messages to the available terminal width to avoid wrapping or overflowing on narrow terminals.

Why

  • Failed edits do not produce meaningful diffs and attempting to render them can cause UI issues.
  • Consistent styling and truncation improve readability and keep the TUI layout stable across different terminal sizes.

@krissetto
Copy link
Contributor

@Pnkcaht Look at the diff edit error at the top on the terminal, we should style it to be consistent with the other tool errors you can see towards the bottom

image

@Pnkcaht
Copy link
Contributor Author

Pnkcaht commented Jan 21, 2026

@Pnkcaht Look at the diff edit error at the top on the terminal, we should style it to be consistent with the other tool errors you can see towards the bottom

Okay, I'll just finish a pull request for an issue I was working on and resolve this, thank you :)

@Pnkcaht
Copy link
Contributor Author

Pnkcaht commented Jan 21, 2026

@krissetto I updated the rendering of the file editing failure to use ToolErrorMessageStyle, matching the error style used by other tools

@krissetto
Copy link
Contributor

for consistency, the tool name needs fixing because it still has the wrong style compared to the screenshot above, and the error/rejection message has to be on the same line (truncated if too long for the current terminal width)
image

@Pnkcaht
Copy link
Contributor Author

Pnkcaht commented Jan 21, 2026

We now display edit_file errors using the same error header layout as other tools: error icon, tool name in error style, and a single-line message truncated to the terminal width. Diff rendering is skipped entirely on failure. @krissetto I was unable to test this locally due to the lack of a running mechanism.

@Pnkcaht
Copy link
Contributor Author

Pnkcaht commented Jan 21, 2026

@krissetto I fixed the X 👍🏻

@krissetto krissetto merged commit e23160e into docker:main Jan 21, 2026
5 checks passed
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.

When edit failed, scrollbar is badly drawn

2 participants