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 lineWrap issues #67

Merged
merged 11 commits into from
Dec 23, 2024
Merged

Fix lineWrap issues #67

merged 11 commits into from
Dec 23, 2024

Conversation

stefanhaller
Copy link
Collaborator

@stefanhaller stefanhaller commented Dec 2, 2024

This fixes several issues with the lineWrap implementation (see individual commit messages for details).

In addition, it changes view highlighting so that in a view with Wrap=true, only the current "physical" line is highlighted, rather than all view lines that belong to the current "logical" line. This is not a breaking change since in lazygit highlighting is only used in views that don't wrap; we want to change that, however.

Finally, it fixes searching for views with Wrap=true.

The test that we're adapting here shows what's wrong: we end up with a wrapped
line that's one character longer than our allowed width.
The space is kept in the wrapped string, which we don't want. Works correctly
for hyphen already.
I don't understand what the `&& lastWhitespaceIndex+1 != i` condition was added
for; I can't see a reason for it. Removing it fixes the problem.

Granted, it's not a serious problem, not even a cosmetic one as the space is not
visible. Still, it's cleaner and less confusing this way.
These work correctly here, but it's good to have the test coverage (there was a
bug related to this case in the lazygit code that copies this algorithm).
Doesn't work correctly yet.
As opposed to "logical" lines, which means that when a long line is wrapped, we
only highlight the actual view line that the cursor is in, rather than all
wrapped view lines that belong to the original, unwrapped line.

This effectively reverts what was done to fix
jroimartin#50, but since we don't need (or want)
this feature in lazygit, we don't bother making this configurable.
I don't see a reason why we should prevent any code from instantiating a view if
they want to. We want to use it in a test in lazygit.
It's surprising to clients if this doesn't happen, and it's a very cheap call,
so we can afford it.
So far, search was only enabled in views with Wrap=false, so it didn't make a
difference. If Wrap is on, we need to work with viewLines rather than lines,
because that's what the code that highlights the search results expects. Note
that a viewLine index is also passed back to the onSelectItem callback, so
clients need to be able to deal with that.

We don't touch the modelSearchResults code path, as it's a bit unclear how to
support Wrap=true in that case, and we don't need it right now.
stefanhaller added a commit to jesseduffield/lazygit that referenced this pull request Dec 2, 2024
Corresponds to the changes in jesseduffield/gocui#67.
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

@stefanhaller stefanhaller merged commit 9967d0e into master Dec 23, 2024
1 check passed
@stefanhaller stefanhaller deleted the fix-lineWrap-issues branch December 23, 2024 11:16
stefanhaller added a commit to jesseduffield/lazygit that referenced this pull request Dec 23, 2024
- **PR Description**

Add a user config (on by default) to turn on line wrapping in the
staging view (and custom patch building view).

Fixes #3558.

This is a bit of a longer PR because I had to fix a bunch of things to
make this possible, and because it takes much more than just turning on
`Wrap` on the staging view.

Usually when I make changes to gocui I include them in the lazygit PR
for easier review; this time, however, the changes required touching
gocui's tests, which are not included in our vendored copy, so I made a
[PR in gocui](jesseduffield/gocui#67) to be
reviewed there, and only included the squashed changes here.

Hot-reloading of the new user config is not perfect: if the staging view
is focused, you need to escape out of it and enter it again for the
change to take affect. I wasn't sure it's worth adding code to fix this.

As for tests: I didn't find a way to add an integration test for this,
as the view geometry is not fixed when you run them locally. But I
didn't look into this very deeply.

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [x] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [x] If a new UserConfig entry was added, make sure it can be
hot-reloaded (see
[here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
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