Repository navigation
fix: stop preview code from overlapping the line numbers - #595
Open
faisalahammad wants to merge 1 commit into
Open
faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
The preview modal scales in as it opens, and CodeMirror was measuring the gutter and character widths while the modal was still scaled down. A transform does not trigger a resize, so CodeMirror never measured again and the code could sit on top of the line numbers. Refresh the editor when the modal frame finishes its animation. Fixes codesnippetspro#448
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
In the snippet preview modal, the code could sit on top of the line numbers. The modal scales in from 90% as it opens, and CodeMirror is set up during that animation, so it measures the gutter and character widths at the smaller scale. A CSS transform does not trigger a resize, so CodeMirror never measures again. This PR refreshes the editor once the modal finishes its opening animation.
Fixes #448
Changes
SnippetPreviewModal.tsxBefore:
After:
Why:
refresh()makes CodeMirror measure again at the final size. When reduced motion is on there is no animation, and there is no bug either. The CodeMirror 6 work in #557 handles the same case withrequestMeasureonanimationend.tests/e2e/code-snippets-preview.spec.tsAdded "Preview code does not overlap the line numbers". It checks that the first line number ends before the first code line starts, with 1px allowed for sub-pixel rounding.
Testing
Test 1: Preview alignment
Result: the line numbers stay in their own column and the code never overlaps them.
Test 2: Fallback and keyboard
Result: the fallback textarea shows with no console errors. Selection works and the code is not editable.
ESLint, Stylelint and the build pass.