[issue18583] Idle: enhance FormatParagraph

Terry J. Reedy report at bugs.python.org
Tue Aug 13 20:54:49 CEST 2013


Terry J. Reedy added the comment:

Based on working with the #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:

1. Extract a list of complete lines (without \n) from the text widget. The only purpose of using selections rather than the cursor would be to get partial paragraphs or multiple paragraphs. (I had thought of deleting that idea, but if you have made it work, I will look at it.)

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.

2. Delete the common prefix from each line, including '#' for comment blocks. Do this and the following without the current repeating joining of and splitting into lines. It is all wasted motion.

3. Reformat into a new list of lines, now with \n.

4. Add back the common prefix (still a list of lines with \n).

5. Insert the lines (which already have \n) into the text widget, one at a time.

   One of the details I left out is consistently handling of \n for the last line, so that deletion from the text widget and inserting into the widget match. One of the 'features' of the current code is that it will handle paragraphs with a different indent on the first line. I am not sure it is needed, as it does not apply to comment and string blocks.

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.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18583>
_______________________________________


More information about the Python-bugs-list mailing list