Avoid empty last line in editable code blocks #1836
Merged
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.
Before, a code block would always end with a final newline. The newline was added unconditionally by
hide_lines
.When the code block is syntax highlighted by highlight.js, this is not a problem, no empty line is added for a final trailing
\n
character. However, when the code block is editable and thus handled by the ACE editor, a trailing newline is significant. I believe this issue is most closely described by ajaxorg/ace#2083 in the upstream repository.The effect of the way ACE handles newlines is that a code block like
will create an editor with two lines, not just one.
By trimming trailing whitespace, we ensure that we don’t accidentally create more lines in the ACE editor than necessary.
Before
After