Fix margin boundary tests in the RI, DL, and IL escape sequences.#1807
Merged
miniksa merged 3 commits intomicrosoft:masterfrom Jul 10, 2019
Merged
Fix margin boundary tests in the RI, DL, and IL escape sequences.#1807miniksa merged 3 commits intomicrosoft:masterfrom
miniksa merged 3 commits intomicrosoft:masterfrom
Conversation
miniksa
approved these changes
Jul 10, 2019
mcpiroman
pushed a commit
to mcpiroman/terminal
that referenced
this pull request
Jul 23, 2019
…crosoft#1807) * Fix margin boundary tests in the RI, DL, and IL sequences. * Refactor the margin boundary tests into a reusable SCREEN_INFORMATION method. * Add screen buffer unit tests for the RI, DL, and IL sequences.
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.
Summary of the Pull Request
When executing an escape sequence that might cause the viewport to scroll, a check is made to see whether the cursor position is in the bounds of the scroll margins, otherwise the scroll operation shouldn't happen. In a couple of cases (in the RI, DL, and IL escape sequence), these boundary tests were incorrect, so the scroll operation would sometimes not occur when it should have. This PR fixes those boundary tests.
Tested manually, and with the joe editor which was previously failing, and with some additional screen buffer unit tests.
PR Checklist
Detailed Description of the Pull Request / Additional comments
The one problem was the use of
Viewport::IsInBoundsmethod to check whether the cursor was inside the margins. That method only works on the first column of the screen, because the horizontal margins are always set to 0. So that needed to be replaced with a test that only checked the y offset against the vertical margins.The other problem was not first checking whether the margins had actually been set. When the margins aren't set, the top and bottom boundaries are both 0, so that needs to be handled as a special case, otherwise it'll only match positions on the first line of the screen.
Having made these fixes in the
DoSrvPrivateReverseLineFeedandDoSrvPrivateModifyLinesImplmethods, I thought it might also be a good idea to refactor the boundary tests into a shared method in theSCREEN_INFORMATIONclass, to try and make the code more readable. I could also then make use of that method to simplify theDoSrvMoveCursorVerticallyimplementation a little.I had initially planned to refactor the
AdjustCursorPositionmethod as well, but I decided against that in the end, because the code is a lot more complicated in that case, and I didn't want to risk potential performance issues given the frequency of its use.In any event, I've committed the refactoring as a separate step, so I can always revert that if you don't think it's a good idea.
Validation Steps Performed
I've added a few screen buffer units tests that make sure the RI, DL, and IL escape sequences basically work, and also specifically check the conditions that were previously failing.
I've also run a few of my own manual tests which check various margin boundary conditions. And I've made sure that the problem with joe editor that was reported in issue #1366 is now working.