Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of \n wrt inserting null cells #68

Merged
merged 5 commits into from
Jan 6, 2025
Merged

Conversation

stefanhaller
Copy link
Collaborator

@stefanhaller stefanhaller commented Jan 5, 2025

This fixes a theoretical problem with overwriting existing lines where a line is exactly one character longer than what's being written; in this case we overwrite the existing character with a null character.

This is only a theoretical problem because to my knowledge we don't overwrite existing text anywhere, at least not in lazygit. The motivation of this PR was not so much to fix the bug, but to simplify the code; this makes it easier to put this PR on top of it.

The test shows a bug with the handling of \n (but not with \r, it works fine
there): if there's exactly one existing character in the current line after the
write position, we overwrite it with a null character. We'll fix this in the
next commit.
This fixes the bug described in the previous commit.

This is the only behavior change in this branch, the rest of the commits are
refactorings to simplify the code.
This has become possible with the previous commit, which made the code identical
between \r and \n.
The readCell function was introduced in e659668 only for this purpose. We
don't need it because:
- the extra check for c.chr == 0 is not needed; if there is already a null cell
  at the line end, we needn't write it again. There is no difference between a
  null cell and a printable cell in this regard
- the only check that's left is for the coordinates; we know that y is valid,
  and x is not less than 0, so the only check we need is for x against the
  length of the line.
Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

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

LGTM. I believe we do overwrite existing text when re-rendering the main view after refreshing so I think this is a practical change, not just theoretical.

@stefanhaller stefanhaller merged commit c80ec09 into master Jan 6, 2025
1 check passed
@stefanhaller stefanhaller deleted the fix-eol-handling branch January 6, 2025 07:57
stefanhaller added a commit to jesseduffield/lazygit that referenced this pull request Jan 6, 2025
This updates gocui to include jesseduffield/gocui#68 and
jesseduffield/gocui#69, which changes views to not have
an extra blank line at the end when content ending in a newline character is
written to them. This makes text views more consistent with list views, which
don't have a blank line after the last list entry either.
stefanhaller added a commit to jesseduffield/lazygit that referenced this pull request Jan 7, 2025
This updates gocui to include jesseduffield/gocui#68 and
jesseduffield/gocui#69, which changes views to not have
an extra blank line at the end when content ending in a newline character is
written to them. This makes text views more consistent with list views, which
don't have a blank line after the last list entry either.
stefanhaller added a commit to jesseduffield/lazygit that referenced this pull request Jan 7, 2025
- **PR Description**

This updates gocui to include
jesseduffield/gocui#68 and
jesseduffield/gocui#69, which changes views to
not have an extra blank line at the end when content ending in a newline
character is written to them. This makes text views more consistent with
list views, which don't have a blank line after the last list entry
either.
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.

2 participants