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: Allow undo/redo on Source > Fix indentation #5657

Merged
merged 2 commits into from
Dec 26, 2017

Conversation

csabella
Copy link
Contributor

@csabella csabella commented Nov 5, 2017

Fixes issue #1754.

Fix indentation converts all the tabs in a document to 4 spaces. Allow undo/redo on this operation.

@ccordoba12 ccordoba12 added this to the v4.0beta2 milestone Nov 5, 2017
# We do the following rather than using self.setPlainText
# to benefit from QTextEdit's undo/redo feature.
self.selectAll()
self.insertPlainText(text_after)
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch!

@goanpeca
Copy link
Member

goanpeca commented Nov 6, 2017

@csabella thanks a lot for working on this. LGTM!

@goanpeca goanpeca requested a review from rlaverde November 6, 2017 14:30
@goanpeca
Copy link
Member

goanpeca commented Nov 6, 2017

@rlaverde want to give it another pass?

@@ -907,12 +907,14 @@ def remove_trailing_spaces(self):
cursor.endEditBlock()

def fix_indentation(self):
"""Replace tabs by spaces"""
"""Replace tabs by 4 spaces."""
Copy link
Member

@goanpeca goanpeca Nov 6, 2017

Choose a reason for hiding this comment

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

@csabella isn't this fix dependent on the preference setting for what a tab should represent? Python is 4 but a user could change this to 3 or 2 if they follow google's ugly style guide.

Not sure this is the case but if it is then.

"""Replace tabs by number of spaces (for tabs) defined in the preferences."""

Copy link
Member

Choose a reason for hiding this comment

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

Yes, @goanpeca is right about this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't use the settings now. It's hard-coded as 4, which is why I made the comment. It's in sourcecode/utils.py.

def fix_indentation(text):
    """Replace tabs by spaces"""
    return text.replace('\t', ' '*4)

Copy link
Member

@goanpeca goanpeca Nov 6, 2017

Choose a reason for hiding this comment

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

@csabella so then we need to fix fix_indentation perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@goanpeca Sure. Should it be in this PR or a separate issue?

Copy link
Member

Choose a reason for hiding this comment

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

I think @dalthviz fixed this one. @dalthviz?

Copy link
Member

Choose a reason for hiding this comment

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

I fixed something regarding the use of preferences but in the comment/uncomment functionality in #5470, is that related with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's similar, but not the same.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, let's leave this for another PR then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opened issue #5678 for the number of spaces.

@@ -84,5 +84,35 @@ def test_selection_indent(code_editor_indent_bot):
)


def test_fix_indentation(code_editor_indent_bot):
"""Test fix_indentation() method."""
ed, qtbot = code_editor_indent_bot
Copy link
Member

Choose a reason for hiding this comment

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

Minor nitpick, but maybe editor is a better word :-), we are not saving that much space bellow anyway.

Copy link
Member

@rlaverde rlaverde left a comment

Choose a reason for hiding this comment

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

LGTM

@ccordoba12 ccordoba12 modified the milestones: v4.0beta2, v4.0beta1 Dec 26, 2017
@ccordoba12 ccordoba12 changed the title PR: Allow undo/redo on Source -> Fix indentation PR: Allow undo/redo on Source > Fix indentation Dec 26, 2017
@ccordoba12 ccordoba12 merged commit f7532b4 into spyder-ide:master Dec 26, 2017
@csabella csabella deleted the issue1754 branch December 26, 2017 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants