Skip to content

Fix color getting removed from wrapped lines - #835

Open
edquist wants to merge 1 commit into
gwsw:masterfrom
edquist:fix-v710-wrapped-color-regression
Open

edquist wants to merge 1 commit into
gwsw:masterfrom
edquist:fix-v710-wrapped-color-regression

Conversation

@edquist

@edquist edquist commented Oct 4, 2026

Copy link
Copy Markdown

v710 introduced a regression where wrapped lines (after the first wrap) would get their color removed when scrolling down (off the top of the screen) and then back up. The initial line retains its coloring, but any wrapped lines afterwards get reset to normal.

For instance:

  --- top ---
  long colored line ...
  wrapped long colored line 1 ...
  wrapped long colored line 2 ...
  wrapped long colored line 3 ...
  wrapped long colored line 4 ...

Now, scroll down 3 lines, and back up 3 lines, then you see:

  --- top ---
  long colored line ...            # still colored
  wrapped long colored line 1 ...  # color reset
  wrapped long colored line 2 ...  # color reset
  wrapped long colored line 3 ...  # still colored
  wrapped long colored line 4 ...  # still colored

You can reproduce with something like:

  echo -e '\x1b[33m' word{1..9999} '\x1b[0m' | less --wordwrap -R

and then scroll down and back up.

This appears to be an unintentional regression, because the color is restored to the wrapped lines if you hit CTRL-L or send less a SIGWINCH.

(My use case is I use less --wordwrap -R as a viewer/reader with my own ansi 'dark mode' theme, with amber text and other markup. It's worked perfectly in the past, but after updating to v710, this regression appeared and it's pretty jarring when I scroll back up, unfortunately.)

I did a git bisect which pointed to f432d2d as the change that introduced the regression.

That commit curiously moved the loop: label in input.c from after the prewind()/plinestart() calls to just before them. Was that intentional? I haven't studied the code carefully enough to say with any confidence. But it is not explained in the commit message and I wonder if it was accidental.

Moving the loop label back to its pre-f432d2d position fixes the color getting removed from wrapped lines regression, and still displays the marks correctly with -J, according to the reproducer steps in #820.

v710 introduced a regression where wrapped lines (after the first
wrap) would get their color removed when scrolling down (off the top of
the screen) and then back up.  The initial line retains its coloring,
but any wrapped lines afterwards get reset to normal.

For instance:

  --- top ---
  long colored line ...
  wrapped long colored line 1 ...
  wrapped long colored line 2 ...
  wrapped long colored line 3 ...
  wrapped long colored line 4 ...

Now, scroll down 3 lines, and back up 3 lines, then you see:

  --- top ---
  long colored line ...            # still colored
  wrapped long colored line 1 ...  # color reset
  wrapped long colored line 2 ...  # color reset
  wrapped long colored line 3 ...  # still colored
  wrapped long colored line 4 ...  # still colored

You can reproduce with something like:

  echo -e '\x1b[33m' word{1..9999} '\x1b[0m' | less --wordwrap -R

and then scroll down and back up.

This appears to be an unintentional regression, because the color is
restored to the wrapped lines if you hit CTRL-L or send less a SIGWINCH.

(My use case is I use `less --wordwrap -R` as a viewer/reader with my
own ansi 'dark mode' theme, with amber text and other markup.  It's worked
perfectly in the past, but after updating to v710, this regression
appeared and it's pretty jarring when I scroll back up, unfortunately.)

I did a git bisect which pointed to f432d2d as the change that
introduced the regression.

That commit curiously moved the `loop:` label in input.c from after the
prewind()/plinestart() calls to just before them.  Was that intentional?
I haven't studied the code carefully enough to say with any confidence.
But it is not explained in the commit message and I wonder if it was
accidental.

Moving the loop label back to its pre-f432d2d position fixes the color
getting removed from wrapped lines regression, and still displays the
marks correctly with `-J`, according to the reproducer steps in gwsw#820.
@gwsw

gwsw commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Moving the loop label in f432d2d was intentional. This patch reintroduces the bug that was fixed in f432d2d.

After applying this patch, run seq 100 | tr '\n' ' ' | LESSNOCONFIG=- ./less -J and enter J m a J K and you will see that the mark letter a does not appear in the status column. I will look into a better way to fix this color issue.

@avih

avih commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Can the test cover such issues? If yes, it's worth adding (both marks and colors with wrapped lines).

@edquist

edquist commented Oct 4, 2026

Copy link
Copy Markdown
Author

After applying this patch, run seq 100 | tr '\n' ' ' | LESSNOCONFIG=- ./less -J and enter J m a J K and you will see that the mark letter a does not appear in the status column.

Ah, ok. The steps to reproduce in #820 had only mentioned typing J m a (which I tried), but not the following J K.

I will look into a better way to fix this color issue.

Cool, thank you!

@gwsw

gwsw commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Yes, lesstest could cover this case. Several of the existing tests check for situations involving colored text. I'm a little surprised that none of them catch this case, but I'll make sure to add a test that does.

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.

3 participants