Skip to content

Fix vi to wrap long lines instead of truncating#555

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-vi-wrap-long-lines
Draft

Fix vi to wrap long lines instead of truncating#555
Copilot wants to merge 5 commits intomainfrom
copilot/fix-vi-wrap-long-lines

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

Summary

Fixed vi to properly wrap long lines across multiple display rows instead of truncating them, as required by POSIX.

Changes Made

  • Investigate the issue and understand the problem
  • Identify that refresh_screen() uses expand_line() which truncates instead of wraps
  • Identify that update_from_buffer() has correct wrapping logic but is unused
  • Fix refresh_screen() to use proper line wrapping
  • Update cursor positioning to account for wrapped lines
  • Run existing tests to ensure no regressions (385 tests pass)
  • Create integration test to verify wrapping works correctly
  • Run clippy to ensure code quality (no warnings)
  • Address code review feedback (guard against zero width, use constants)
  • Run security scan (no issues)
  • Fix formatting issues with cargo fmt

Technical Details

Modified Files:

  • editors/vi/ui/screen.rs: Made expand_and_wrap_line() public
  • editors/vi/editor.rs: Rewrote refresh_screen() to properly wrap lines and position cursor
  • editors/tests/pty/mod.rs: Added integration test for line wrapping

Key Implementation:

  1. refresh_screen() now iterates through wrapped rows instead of assuming 1 buffer line = 1 screen row
  2. Added calculate_cursor_screen_row() to compute cursor position accounting for wrapped lines
  3. Cursor column calculation now uses modulo to find position within wrapped row
  4. Added safety guards against division by zero for narrow terminals

Testing

All existing tests pass (385 tests), new test added specifically for wrapping behavior.

Original prompt

This section details on the original issue you should resolve

<issue_title>vi wrap long lines</issue_title>
<issue_description>Hi.
vi doesn't wrap long lines by default.

Compare the behavior of the vi with the behavior of the ex
printf %b {1..100} \n >file
vi file
The vi shows only one line of text per terminal width

ex file
:%p

The ex shows the full wrapped text.</issue_description>

<agent_instructions>Review POSIX spec for vi then proceed</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits February 8, 2026 07:33
- Made expand_and_wrap_line() public in screen.rs
- Rewrote refresh_screen() to use wrapped lines instead of truncation
- Added calculate_cursor_screen_row() to properly position cursor with wrapped lines
- Fixed cursor column calculation to account for wrapping within a line

Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
Added test_pty_vi_long_line_wrapping to verify that vi correctly wraps long lines across multiple display rows instead of truncating them.

Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
- Add guard against zero/very small terminal width to prevent division by zero
- Replace magic string '        ' with LINE_NUMBER_WIDTH constant for consistency
- Add named constant for test line length
- Add early return when terminal is too narrow to display content

Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix vi behavior for wrapping long lines Fix vi to wrap long lines instead of truncating Feb 8, 2026
Copilot AI requested a review from jgarzik February 8, 2026 07:37
Copy link
Contributor

@jgarzik jgarzik left a comment

Choose a reason for hiding this comment

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

CI fails. you must run cargo fmt

Co-authored-by: jgarzik <494411+jgarzik@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 8, 2026

CI fails. you must run cargo fmt

Fixed in 8f34320. Ran cargo fmt --all to format the code according to Rust standards.

Copilot AI requested a review from jgarzik February 8, 2026 13:41
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.

vi wrap long lines

2 participants