MCPcopy Index your code
hub / github.com/python/cpython / delete

Method delete

Lib/idlelib/idle_test/mock_tk.py:219–248  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)

Callers 15

tearDownMethod · 0.45
tearDownMethod · 0.45
tearDownMethod · 0.45
test_deleteMethod · 0.45
_assert_highlightingMethod · 0.45
next_testFunction · 0.45
runcaseMethod · 0.45
test_short_lineMethod · 0.45
test_long_lineMethod · 0.45
test_multiple_linesMethod · 0.45
test_comment_blockMethod · 0.45

Calls 1

_decodeMethod · 0.95

Tested by 15

tearDownMethod · 0.36
tearDownMethod · 0.36
tearDownMethod · 0.36
test_deleteMethod · 0.36
_assert_highlightingMethod · 0.36
next_testFunction · 0.36
runcaseMethod · 0.36
test_short_lineMethod · 0.36
test_long_lineMethod · 0.36
test_multiple_linesMethod · 0.36
test_comment_blockMethod · 0.36