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

Method smart_backspace_event

Lib/idlelib/editor.py:1298–1339  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

1296 self.set_tk_tabwidth(self.tabwidth)
1297
1298 def smart_backspace_event(self, event):
1299 text = self.text
1300 first, last = self.get_selection_indices()
1301 if first and last:
1302 text.delete(first, last)
1303 text.mark_set("insert", first)
1304 return "break"
1305 # Delete whitespace left, until hitting a real char or closest
1306 # preceding virtual tab stop.
1307 chars = text.get("insert linestart", "insert")
1308 if chars == '':
1309 if text.compare("insert", ">", "1.0"):
1310 # easy: delete preceding newline
1311 text.delete("insert-1c")
1312 else:
1313 text.bell() # at start of buffer
1314 return "break"
1315 if chars[-1] not in " \t":
1316 # easy: delete preceding real char
1317 text.delete("insert-1c")
1318 return "break"
1319 # Ick. It may require *inserting* spaces if we back up over a
1320 # tab character! This is written to be clear, not fast.
1321 tabwidth = self.tabwidth
1322 have = len(chars.expandtabs(tabwidth))
1323 assert have > 0
1324 want = ((have - 1) // self.indentwidth) * self.indentwidth
1325 # Debug prompt is multilined....
1326 ncharsdeleted = 0
1327 while True:
1328 chars = chars[:-1]
1329 ncharsdeleted = ncharsdeleted + 1
1330 have = len(chars.expandtabs(tabwidth))
1331 if have <= want or chars[-1] not in " \t":
1332 break
1333 text.undo_block_start()
1334 text.delete("insert-%dc" % ncharsdeleted, "insert")
1335 if have < want:
1336 text.insert("insert", ' ' * (want - have),
1337 self.user_input_insert_tags)
1338 text.undo_block_stop()
1339 return "break"
1340
1341 def smart_indent_event(self, event):
1342 # if intraline selection:

Callers 1

Calls 10

get_selection_indicesMethod · 0.95
deleteMethod · 0.45
mark_setMethod · 0.45
getMethod · 0.45
compareMethod · 0.45
bellMethod · 0.45
expandtabsMethod · 0.45
undo_block_startMethod · 0.45
insertMethod · 0.45
undo_block_stopMethod · 0.45

Tested by

no test coverage detected