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
Idle: enhance FormatParagraph #62783
Comments
Writing tests for FormatParagraph.py bpo-18226 revealed that it could use some improvements. At minimum, some for format_paragraph should probably be replaced with textwrap.wrap (or the class) in order to handles double spacing after sentences. Find_paragraph should find the boundaries of triple-quoted strings. The current end-of-text behavior of find_paragraph should perhaps be changed. |
In the case of no selection would it make sense to only format if the cursor is in a string/comment? If not in a string or comment, the single line that the cursor is in could be formatted with a line ending backslash or not at all. Otherwise Format Paragraph will probably just be mangling code. |
I've attached a patch that attempts to address the issues above. For the tests, I made some changes because the cursor doesn't end in exactly the same spot with line endings. Here's a quick summary of the changes:
Once I have some feedback, I can thoroughly check all of the tests and make sure that we're getting the expected behavior. |
Based on working with the bpo-18226 patch, I now think that rewrapping partial lines is a bug. Although I removed some problematical tests, I think there is still one that verifies buggy behavior. The outline of steps (which necessarily omits some details) would then be:
There are still details to work out. If the cursor is on a blank line, should we really search forward? Normally, sel.first would be moved back to the beginning of the line [you apparently have already done this] and sel.last to the end. But if a block selection ends at the beginning of a line, sel.last should not be moved.
Steps 2,3,4 do not involve the text widget. I think that they should be performed in one or more non-widget functions so they can be separately tested. I would feel this way even if mock_tk.Text were complete enough to substitute for tkinter.Text in the method test. I have not looked at your patch much because I want to review and possibly edit and commit some of the other submitted test patches before working more on this. |
Note to myself. The current test suite has one test commented out because it worked with EditorWindow but not the mock. It is possible that it is a mark-gravity issue. (I ran into this with the mock for IdleHistory.). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: