Delete slice from index1 to index2 (default is 'index1+1'). Adjust default index2 ('index+1) for line ends. Do not delete the terminal \n at the very end of self.data ([-1][-1]).
(self, index1, index2=None)
| 217 | return ''.join(lines) |
| 218 | |
| 219 | def delete(self, index1, index2=None): |
| 220 | '''Delete slice from index1 to index2 (default is 'index1+1'). |
| 221 | |
| 222 | Adjust default index2 ('index+1) for line ends. |
| 223 | Do not delete the terminal \n at the very end of self.data ([-1][-1]). |
| 224 | ''' |
| 225 | startline, startchar = self._decode(index1, -1) |
| 226 | if index2 is None: |
| 227 | if startchar < len(self.data[startline])-1: |
| 228 | # not deleting \n |
| 229 | endline, endchar = startline, startchar+1 |
| 230 | elif startline < len(self.data) - 1: |
| 231 | # deleting non-terminal \n, convert 'index1+1 to start of next line |
| 232 | endline, endchar = startline+1, 0 |
| 233 | else: |
| 234 | # do not delete terminal \n if index1 == 'insert' |
| 235 | return |
| 236 | else: |
| 237 | endline, endchar = self._decode(index2, -1) |
| 238 | # restricting end position to insert position excludes terminal \n |
| 239 | |
| 240 | if startline == endline and startchar < endchar: |
| 241 | self.data[startline] = self.data[startline][:startchar] + \ |
| 242 | self.data[startline][endchar:] |
| 243 | elif startline < endline: |
| 244 | self.data[startline] = self.data[startline][:startchar] + \ |
| 245 | self.data[endline][endchar:] |
| 246 | startline += 1 |
| 247 | for i in range(startline, endline+1): |
| 248 | del self.data[startline] |
| 249 | |
| 250 | def compare(self, index1, op, index2): |
| 251 | line1, char1 = self._decode(index1) |