Repository navigation
COOKED_READ_DATA: Fix scrolling under ConPTY - #15930
Merged
Dustin L. Howett (DHowett) merged 1 commit intoSep 8, 2023
Merged
Conversation
Leonard Hecker (lhecker)
force-pushed
the
dev/lhecker/15899-cooked-read-fixup
branch
2 times, most recently
from
September 5, 2023 14:51
1bc9a02 to
9a9cd5c
Compare
Leonard Hecker (lhecker)
force-pushed
the
dev/lhecker/15899-cooked-read-fixup
branch
from
September 6, 2023 15:24
9a9cd5c to
0e20dcd
Compare
| else if (writingMethod == PrintWithWriteCharsLegacy) | ||
| { | ||
| WriteCharsLegacy(si, str, true, nullptr); | ||
| WriteCharsLegacy(si, str, false, nullptr); |
Member
Author
There was a problem hiding this comment.
This makes the tests pass. I don't think they ever relied on the interactive behavior of WriteCharsLegacy.
| const auto distanceAfterCursor = _writeChars(view.substr(_bufferCursor)); | ||
| const auto distanceEnd = distanceBeforeCursor + distanceAfterCursor; | ||
| const auto eraseDistance = std::max(0, _distanceEnd - distanceEnd); | ||
| const auto eraseDistance = std::max<ptrdiff_t>(0, _distanceEnd - distanceEnd); |
Member
Author
There was a problem hiding this comment.
After a lot of back and forth, I went with ptrdiff_t after all. That way we can have bigger buffers in the future and make full use of our int32_t coordinates.
| const auto finalCursorPos = cursor.GetPosition(); | ||
| return (finalCursorPos.y - initialCursorPos.y + scrollY) * width + finalCursorPos.x - initialCursorPos.x; | ||
| const auto distance = (finalCursorPos.y - initialCursorPos.y + scrollY) * width + finalCursorPos.x - initialCursorPos.x; | ||
| assert(distance >= 0); |
Member
Author
There was a problem hiding this comment.
This helped me find the 2nd bug.
Comment on lines
+143
to
+144
| ptrdiff_t _distanceCursor = 0; | ||
| ptrdiff_t _distanceEnd = 0; |
Member
Author
There was a problem hiding this comment.
Whoops. Forgot to 0 initialize.
Carlos Zamora (carlos-zamora)
approved these changes
Sep 7, 2023
Dustin L. Howett (DHowett)
approved these changes
Sep 8, 2023
Dustin L. Howett (DHowett)
deleted the
dev/lhecker/15899-cooked-read-fixup
branch
September 8, 2023 22:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit fixes 3 bugs:
COOKED_READ_DATAfailed to initialize its_distanceCursorand_distanceEndmembers. I took this as an opportunity to make themptrdiff_t, to reduce the likelihood of overflows in the future.COOKED_READ_DATA::_writeCharsaddedscrollYto the writtendistance, even though
WriteCharsLegacywrites a negative value intothat out parameter. This was fixed by changing
WriteCharsLegacytowrite positive values and by adding a debug assertion.
StreamScrollRegioncallsIncrementCircularBufferwhich causes asynchronous (!) ConPTY flush to the output pipe (side note: this is
the primary reason why newlines are so slow in ConPTY).
Since cooked reads are supposed to behave like a pager and not write
into the scrollback, we temporarily mark the buffer as inactive
which prevents
TextBufferfrom snitching about it to VtEngine.Even after this change, there's still some weird behavior left:
real pager-like implementation. That might be a neat future extension.
cursor and scroll the buffer, unless the cursor is at the end.
That might also be worth investigating in the future (minor issue).
(using Ctrl+Backspace) doesn't erase all of the affected lines,
because
COOKED_READ_DATA::_eraseuses the sameWriteCharsLegacyfunction to write whitespace to erase that text. It's only gone
after typing one more character.
I've written the code to mostly fix this, but decided against it
as I considered the problem to be too niche to warrant extra code.
Closes #15899
Validation Steps Performed