Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Fix extra line in range when formatting selection #21654

Merged
merged 1 commit into from
Dec 30, 2023

Conversation

remisalmon
Copy link
Contributor

@remisalmon remisalmon commented Dec 27, 2023

Description of Changes

  • Wrote at least one-line docstrings (for any new functions)
  • Added unit test(s) covering the changes (if testable)
  • Included a screenshot or animation (if affecting the UI, see Licecap)

This fixes an issue where formatting a line selected by a double click includes and formats the next line.

In some cases this even breaks the code; when using black and selecting a line outside the range of the text the formatting wraps around:

> cat -n temp.py
     1	a = 'hello'
     2	b = ["a", "very", "very", "very", "very", "very", "very", "very", "very", "long", "line"]
     3	c =  42

> black --diff --line-ranges 3-3 temp.py
--- temp.py	2023-12-27 04:53:07.369501+00:00
+++ temp.py	2023-12-27 04:58:40.860306+00:00
@@ -1,3 +1,3 @@
 a = 'hello'
 b = ["a", "very", "very", "very", "very", "very", "very", "very", "very", "long", "line"]
-c =  42
+c = 42
would reformat temp.py

> black --diff --line-ranges 3-4 temp.py
--- temp.py	2023-12-27 04:53:07.369501+00:00
+++ temp.py	2023-12-27 04:58:57.782151+00:00
@@ -1,3 +1,15 @@
-a = 'hello'
-b = ["a", "very", "very", "very", "very", "very", "very", "very", "very", "long", "line"]
-c =  42
+a = "hello"
+b = [
+    "a",
+    "very",
+    "very",
+    "very",
+    "very",
+    "very",
+    "very",
+    "very",
+    "very",
+    "long",
+    "line",
+]
+c = 42
would reformat temp.py 

Note sure if a bug or a feature, https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#line-ranges says that

Black may still format lines outside of the ranges for multi-line statements.

This issue (minus the wraparound thing) also exists and is fixed with autopep8.

Before:

Screen.Recording.2023-12-26.at.9.51.44.PM.mp4

After:

Screen.Recording.2023-12-26.at.9.52.45.PM.mp4

Issue(s) Resolved

None, let me know if I need to create one?

Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the Developer Certificate of Origin
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

I certify the above statement is true and correct: remisalmon

@ccordoba12 ccordoba12 changed the title Fix extra line in range when formatting selection PR: Fix extra line in range when formatting selection Dec 27, 2023
@ccordoba12 ccordoba12 added this to the v5.5.1 milestone Dec 27, 2023
Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks @remisalmon!

@ccordoba12 ccordoba12 merged commit 87772f3 into spyder-ide:5.x Dec 30, 2023
22 checks passed
ccordoba12 added a commit that referenced this pull request Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants