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(column)!: ensure 'statuscolumn' works with virtual and wrapped lines #21768

Merged
merged 2 commits into from
Jan 16, 2023

Conversation

luukvbaal
Copy link
Contributor

@luukvbaal luukvbaal commented Jan 12, 2023

fix(column)!: ensure 'statuscolumn' works with virtual and wrapped lines

Problem: The 'statuscolumn' was not re-evaluated for wrapped lines, when preceded by virtual/filler lines. There was also no way to distinguish virtual and wrapped lines in the status column.

Solution: Make sure to rebuild the statuscolumn, and replace variable v:wrap with v:virtnum. v:virtnum is negative when drawing virtual lines, zero when drawing the actual buffer line, and positive when drawing the wrapped part of a buffer line.

Also resolve a memory leak when returning from win_line() by breaking instead of returning.

fix(column): avoid drawing columns for virt_lines_leftcol

Problem: The default fold column, as well as the 'statuscolumn', were drawn unnecessarily/unexpectedly for virtual lines placed with virt_lines_leftcol set.

Solution: Skip the column states if a virtual line with virt_lines_leftcol set will be drawn.

@luukvbaal
Copy link
Contributor Author

luukvbaal commented Jan 12, 2023

I guess this actually revealed an issue, only tested with diff-mode filler lines before. Now we also rebuild the statuscolumn for the first wrapped line after filler lines.

@luukvbaal luukvbaal changed the title test(statuscolumn): add virt_lines test for filler lines fix(statuscolumn): rebuild statuscolumn on wrapped line after virt_lines Jan 12, 2023
@lewis6991
Copy link
Member

It's hard to tell from the test, but statuscolumn should not be rendered at all for virtual lines.

@luukvbaal
Copy link
Contributor Author

It's hard to tell from the test, but statuscolumn should not be rendered at all for virtual lines.

Hmm why? Isn't the point of statuscolumn to let the user decide how their "gutter" will look? Seems arbitrary to exclude virtual lines from this, e.g. with a column border:
image

I would be more in favor of introducing a v:virtline (or something) variable if it needs to be distinguishable from v:wrap.

@lewis6991
Copy link
Member

Hmm ok maybe, but we need to make sure virt_lines_leftcol is properly handled.

@luukvbaal
Copy link
Contributor Author

luukvbaal commented Jan 12, 2023

Oof, seems to work actually. However it is drawn over the statuscolumn, is that okay?
image
Or should statuscolumn not be drawn for virt_lines_leftcol lines?

@zeertzjq zeertzjq added column sign/number column and removed test labels Jan 13, 2023
@marvim marvim requested a review from lewis6991 January 13, 2023 03:20
@lewis6991
Copy link
Member

Oof, seems to work actually. However it is drawn over the statuscolumn, is that okay?

Not really.

Or should statuscolumn not be drawn for virt_lines_leftcol lines?

Yes

@luukvbaal
Copy link
Contributor Author

luukvbaal commented Jan 13, 2023

Oof, seems to work actually. However it is drawn over the statuscolumn, is that okay?

Not really.

Or should statuscolumn not be drawn for virt_lines_leftcol lines?

Yes

The same is true for the default fold column BTW, should that be considered a bug as well then? This is some virt_lines_leftcol lines without 'statuscolumn' set:
image

@luukvbaal
Copy link
Contributor Author

luukvbaal commented Jan 13, 2023

Should virtual lines have l:wrap set, even though they precede the real line rather than being its continuation? It produces correct behavior in terms of %l/%s not displaying anything on those lines by default, but it seems like there should be a separate v: value to indicate it so users can detect the difference.

I would be more in favor of introducing a v:virtline (or something) variable if it needs to be distinguishable from v:wrap.

Proposal

Rename v:wrap to v:virtline(?) and set it's value to:

  • -1 for filler_lines above the actual buffer line.
  • 0 for the actual buffer line
  • 1 for the wrapped part of lines

User can check that v:virtline == / < / > 0. Seems better than adding a new variable.

Alternatively we could set it to row - startrow - filler_lines(v:virtnum) to have it indicate the distance to the actual buffer line. Not sure that that would be useful but I guess it wouldn't hurt.

@luukvbaal luukvbaal changed the title fix(statuscolumn): rebuild statuscolumn on wrapped line after virt_lines fix(column)!: ensure 'statuscolumn' works with virtual and wrapped lines Jan 15, 2023
runtime/doc/eval.txt Outdated Show resolved Hide resolved
@luukvbaal luukvbaal force-pushed the test-virtline branch 2 times, most recently from f3a28de to 6f20bca Compare January 15, 2023 01:59
@luukvbaal
Copy link
Contributor Author

Do we need newst.txt updates for breaking changes on unreleased features?

@zeertzjq
Copy link
Member

This change is probably to small to mention as these variables aren't mentioned either.

src/nvim/drawline.c Outdated Show resolved Hide resolved
@luukvbaal luukvbaal force-pushed the test-virtline branch 2 times, most recently from 1b9ab1f to 582be0e Compare January 15, 2023 03:17
Problem:    The `'statuscolumn'` was not re-evaluated for wrapped lines,
            when preceded by virtual/filler lines. There was also no way
            to distinguish virtual and wrapped lines in the status column.
Solution:   Make sure to rebuild the statuscolumn, and replace variable
            `v:wrap` with `v:virtnum`. `v:virtnum` is negative when drawing
            virtual lines, zero when drawing the actual buffer line, and
            positive when drawing the wrapped part of a buffer line.
@luukvbaal
Copy link
Contributor Author

e627053 fixes this issue #21768 (comment). It might be better discussed in a separate PR but it depends on this so I added it here.

Copy link
Member

@lewis6991 lewis6991 left a comment

Choose a reason for hiding this comment

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

LGTM

test/functional/ui/statuscolumn_spec.lua Outdated Show resolved Hide resolved
test/functional/ui/statuscolumn_spec.lua Outdated Show resolved Hide resolved
Problem:    The default fold column, as well as the 'statuscolumn', were
            drawn unnecessarily/unexpectedly for virtual lines placed
            with `virt_lines_leftcol` set.
Solution:   Skip the column states if a virtual line with
            `virt_lines_leftcol` set will be drawn.
@phgz
Copy link

phgz commented Nov 3, 2023

Alternatively we could set it to row - startrow - filler_lines(v:virtnum) to have it indicate the distance to the actual buffer line. Not sure that that would be useful but I guess it wouldn't hurt.

This could be nice to have actually. I am trying to do a different action depending on the relative wrapped line position to the actual buffer line. Also, it would not be breaking change.

@luukvbaal
Copy link
Contributor Author

I would be okay with this. It would mean 'statuscolumn' is re-evaluated for each line in the window, currently it is only re-evaluated once for filler lines above the buffer line, once for the buffer line itself, and once for the wrapped lines below. So there would be a performance hit as well, but not compared to buffers where 'wrap' is disabled anyways. So not something we have to worry about I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change column sign/number column
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants