Return line information about the selected text region. If text is selected, the first and last indices will be for the selection. If there is no text selected, the indices will be the current cursor location. Return a tuple containing (first index, last index,
(self)
| 216 | self.editwin = editwin |
| 217 | |
| 218 | def get_region(self): |
| 219 | """Return line information about the selected text region. |
| 220 | |
| 221 | If text is selected, the first and last indices will be |
| 222 | for the selection. If there is no text selected, the |
| 223 | indices will be the current cursor location. |
| 224 | |
| 225 | Return a tuple containing (first index, last index, |
| 226 | string representation of text, list of text lines). |
| 227 | """ |
| 228 | text = self.editwin.text |
| 229 | first, last = self.editwin.get_selection_indices() |
| 230 | if first and last: |
| 231 | head = text.index(first + " linestart") |
| 232 | tail = text.index(last + "-1c lineend +1c") |
| 233 | else: |
| 234 | head = text.index("insert linestart") |
| 235 | tail = text.index("insert lineend +1c") |
| 236 | chars = text.get(head, tail) |
| 237 | lines = chars.split("\n") |
| 238 | return head, tail, chars, lines |
| 239 | |
| 240 | def set_region(self, head, tail, chars, lines): |
| 241 | """Replace the text between the given indices. |