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

Extension is not activated with highlighted text and pressing ENTER #28

Closed
WhistleWhileYouWork opened this issue Jul 4, 2019 · 7 comments

Comments

@WhistleWhileYouWork
Copy link
Contributor

WhistleWhileYouWork commented Jul 4, 2019

First off, thank you for putting in the time to create and share this nifty little tool!

I noticed the following minor inconsistency and I thought I would share it just in case it was important (personally I can live with it) or if the fix is simple (I'm guessing this may only require also registering the ENTER key for the extension when text is highlighted). At the very least, I suggest putting this in the Caveats section.

Minimal code example:

What the code looks like before pressing enter:

my_dict = {'a': 1, |'b': 2}
# Now highlight the space between the dict entries to bring 'b' to a new line and eliminate the would-be trailing space

What I want the code to look like after pressing enter:

my_dict = {'a': 1,
           'b': 2}|
# No trailing space and code is aligned

What the code actually looks like after pressing enter:

my_dict = {'a': 1,
'b': 2}|
# No trailing space but code is not aligned

Often times, we have to go back and change our code and sometimes we run up against linting line limits when we add to a line of code. We then have to choose a place to break the line into two lines. Invariably this logical break occurs at a separation point that involves a space. In order to avoid getting lint-bombed, we delete the space. I prefer to highlight the space and hit ENTER. I'm sure that there are a lot of keyboard-only people that will never encounter this and the alternative of course is to simply delete the space before or after hitting ENTER.

Environment (please complete the following information):

  • Python Indent version: [e.g. 1.0.0]
  • Visual Studio Code version: [e.g. 1.35.1]
  • OS: Windows 10 1809 64 bit
@kbrose
Copy link
Owner

kbrose commented Jul 4, 2019

Good use case, good write up. Thanks for the issue!

I specifically have the extension set to not run when there is text highlighted (see the !editorHasSelection portion), but to be honest I don't remember why. Maybe it doesn't delete the highlighted text if my extension runs in that case?

I imagine most of the time spent on this issue will be trying to figure out what poor behaviors come from allowing it to run when text is highlighted, and how to mitigate them.

@kbrose
Copy link
Owner

kbrose commented Jul 4, 2019

Minor nitpick, shouldn't the desired behavior be

my_dict = {'a': 1,
           'b': 2}
# No trailing space and code is aligned

instead of

my_dict = {'a': 1,
                  'b': 2}
# No trailing space and code is aligned

?

@WhistleWhileYouWork
Copy link
Contributor Author

Yikes! That is NOT how it looked when I submitted or previewed it. Now when I go to edit it, I have to take off spaces and check the preview to make sure it's aligned. The two views are not the same! Very strange. I guess I'm going to have to double-check the post after posting too.

@WhistleWhileYouWork
Copy link
Contributor Author

I'm surprised you didn't document that. Your documentation is very thorough.

I specifically have the extension set to not run when there is text highlighted

I can change that setting in my package.json for your extension and test it out and provide feedback.

I think the reason my alignment for the code was off is because the font is not fixed-width. Any idea how to change that? It should be a GitHub setting now a browser one.

@WhistleWhileYouWork
Copy link
Contributor Author

OK after removing !editorHasSelection and !editorHasMultipleSelections from lines 32 and 37 of package.json, the space from the beginning of the selection on the first line to the end of the selection on the new line is still highlighted.

The pipes and dots in between represent the highlighted section:

my_dict = {'a': 1,|
..........|'b': 2}

@WhistleWhileYouWork
Copy link
Contributor Author

It turns out the selected text wasn't even being deleted (since the extension was now responsible for doing it). All that was needed was 4 lines of code at the beginning to delete the selection first. I submitted a pull request.

@kbrose
Copy link
Owner

kbrose commented Jul 14, 2019

This should now work correctly in version 1.1.0. Please upgrade and re-open if the issue persists.

@kbrose kbrose closed this as completed Jul 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants