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

Position the conpty cursor correctly when wrappedRow is set #17290

Merged
merged 3 commits into from
May 30, 2024

Conversation

j4james
Copy link
Collaborator

@j4james j4james commented May 18, 2024

Summary of the Pull Request

If the VT render engine is moving the cursor to the start of a row, and
the previous row was marked as wrapped, it will assume that it doesn't
need to do anything, because the next output should automatically move
the cursor to the correct position anyway.

However, if that cursor movement is coming from the final PaintCursor
call for the frame, there isn't going to be any more output, so the
cursor will be left in the wrong position.

This PR fixes that issue by clearing the _wrappedRow field before the
_MoveCursor call in the PaintCursor method.

Validation Steps Performed

I've confirmed that this fixes all the test cases mentioned in issue
#17270, and issue #17013, and I've added a unit test to check the new
behavior is working as expected.

However, this change does break a couple of ConptyRoundtripTests that
were expecting the terminal row to be marked as wrapped when writing a
wrapped line in two parts using WriteCharsLegacy. This is because the
legacy way of wrapping a line isn't the same as a VT delayed wrap, so it
has to be emulated with cursor movement, and that can end up resetting
the wrap flag.

It's possible that could be fixed, but it's already broken in a number
of other ways, so I don't think this makes things much worse. For now,
I've just made the affected test cases skip the wrapping check.

PR Checklist

@j4james
Copy link
Collaborator Author

j4james commented May 19, 2024

In an ideal world the wrapping code needs a major rewrite, so if that's something someone is already planning to do, you may want to ignore this and wait for a proper fix. But if you want a quick resolution to #17270, this may be the least worst option for now. And I think having the cursor correctly positioned is way more important than regressing a few reflow wrapping cases that were never fully working to begin with.

@lhecker
Copy link
Member

lhecker commented May 19, 2024

Before I say anything else: This is great! I think we should merge this because alternatives won't arrive any time soon.

In an ideal world the wrapping code needs a major rewrite, so if that's something someone is already planning to do, you may want to ignore this and wait for a proper fix.

FYI coincidentally I did start writing a ConPTY variant today that does straight conversions to VT and has no VtEngine at all. Basic usage of pwsh and wsl already works. I believe the main complexity of the work will be the rewrite of cooked read in terms of VT sequences without direct TextBuffer access, removing all the "passthrough" logic out of the VT parser, as well as finding the numerous edge cases, like how we need to restore win32-input-mode when encountering reset sequences. I'm confident I can get a version out in ~a month that certainly will have bugs but should already be useable. 🙂
I'm sure the initial bugs will not be great, but working on it today I found that resolving these is significantly easier when the Renderer code isn't in the way. Store a flag here, add a check there, and everything's entirely synchronous. Well, it was "easier" so far at least (and in my opinion). 😅

@zadjii-msft zadjii-msft added this pull request to the merge queue May 30, 2024
Merged via the queue into microsoft:main with commit ad362fc May 30, 2024
13 of 15 checks passed
@zadjii-msft zadjii-msft added this to the Terminal v1.22 milestone May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants