Formats paragraph to a max width specified in idleConf. If text is selected, format_paragraph_event will start breaking lines at the max width, starting from the beginning selection. If no text is selected, format_paragraph_event uses the current cursor location to
(self, event, limit=None)
| 40 | self.editwin = None |
| 41 | |
| 42 | def format_paragraph_event(self, event, limit=None): |
| 43 | """Formats paragraph to a max width specified in idleConf. |
| 44 | |
| 45 | If text is selected, format_paragraph_event will start breaking lines |
| 46 | at the max width, starting from the beginning selection. |
| 47 | |
| 48 | If no text is selected, format_paragraph_event uses the current |
| 49 | cursor location to determine the paragraph (lines of text surrounded |
| 50 | by blank lines) and formats it. |
| 51 | |
| 52 | The length limit parameter is for testing with a known value. |
| 53 | """ |
| 54 | limit = self.max_width if limit is None else limit |
| 55 | text = self.editwin.text |
| 56 | first, last = self.editwin.get_selection_indices() |
| 57 | if first and last: |
| 58 | data = text.get(first, last) |
| 59 | comment_header = get_comment_header(data) |
| 60 | else: |
| 61 | first, last, comment_header, data = \ |
| 62 | find_paragraph(text, text.index("insert")) |
| 63 | if comment_header: |
| 64 | newdata = reformat_comment(data, limit, comment_header) |
| 65 | else: |
| 66 | newdata = reformat_paragraph(data, limit) |
| 67 | text.tag_remove("sel", "1.0", "end") |
| 68 | |
| 69 | if newdata != data: |
| 70 | text.mark_set("insert", first) |
| 71 | text.undo_block_start() |
| 72 | text.delete(first, last) |
| 73 | text.insert(first, newdata) |
| 74 | text.undo_block_stop() |
| 75 | else: |
| 76 | text.mark_set("insert", last) |
| 77 | text.see("insert") |
| 78 | return "break" |
| 79 | |
| 80 | |
| 81 | FormatParagraph.reload() |
nothing calls this directly
no test coverage detected