Repository navigation
fix #1057: Preserve indentation when pasting code blocks - #1059
Open
Piyush13104 wants to merge 1 commit into
Open
Piyush13104 wants to merge 1 commit into
Piyush13104 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1059 +/- ##
==========================================
- Coverage 76.51% 76.31% -0.21%
==========================================
Files 62 61 -1
Lines 8308 8346 +38
==========================================
+ Hits 6357 6369 +12
- Misses 1951 1977 +26 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #1057.
Pasting indented code could lose its indentation entirely. Reproduced by
driving bpython in a pty and rendering the screen through a terminal
emulator; there turned out to be two independent causes.
Tab events were dropped.
just_simple_events()discarded any eventwith
len(e) > 1that was not explicitly whitelisted, and<TAB>wasnot on the list, so tab-indented code lost all indentation and produced
the reporter's exact error.
preprocess.leading_tabs_to_spaces()existsto convert pasted tabs, but was unreachable because tabs never survived
to reach it.
Runs of spaces were collapsed.
compress_paste_event()treats a runof identical named keys as a held-down key.
<SPACE>is a named key incurtsies, so any read of 8 or more consecutive spaces (the paste
threshold is 7 bytes) collapsed to one. Twelve pasted spaces produced a
single space.
just_simple_events(),is_simple_event()andcompress_paste_event()each kept their own copy of the same list of text-producing keys and had
drifted apart, which is how
<TAB>was missed. They now share aCONTENT_KEYStable.Fixing those exposed a third problem: a statement at column 0 after a
block was swallowed into it, because pasted code has no blank line to
close the block.
separate_blocks()inserts one. It distinguishes ablock awaiting its blank line from a buffer held open by an unclosed
bracket by testing whether appending blank lines makes it compile, and
leaves
elif/else/except/finallyand comments alone, soif/elseandtry/exceptpastes are untouched.The script from the issue now pastes and runs correctly. Added 17 tests
covering tab- and space-indented pastes, deep indentation, continuing
clauses, unindented bracket continuations, decorators, multi-line
strings and backslash continuations.