@@ -1338,6 +1338,23 @@ def set_indentation_params(self, is_py_src, guess=True):
13381338 self .usetabs = False
13391339 self .set_tk_tabwidth (self .tabwidth )
13401340
1341+ @staticmethod
1342+ def delete_trail_whitespace (want , chars , tabwidth ):
1343+ ncharsdeleted = 0
1344+ have = len (chars .expandtabs (tabwidth ))
1345+ for i in range (len (chars ) - 1 , - 1 , - 1 ):
1346+ # ``Delete'' chars[i], and subtract count
1347+ # (since redoing expandtabs is O(n))
1348+ ncharsdeleted += 1
1349+ if chars [i ] == '\t ' :
1350+ have -= tabwidth
1351+ else :
1352+ have -= 1
1353+ if have <= want or chars [i - 1 ] not in " \t " :
1354+ break
1355+ chars = chars [:len (chars ) - ncharsdeleted ]
1356+ return ncharsdeleted , chars
1357+
13411358 def smart_backspace_event (self , event ):
13421359 text = self .text
13431360 first , last = self .get_selection_indices ()
@@ -1366,19 +1383,7 @@ def smart_backspace_event(self, event):
13661383 assert have > 0
13671384 want = ((have - 1 ) // self .indentwidth ) * self .indentwidth
13681385 # Debug prompt is multilined....
1369- ncharsdeleted = 0
1370- have = len (chars .expandtabs (tabwidth ))
1371- for i in range (len (chars ) - 1 , - 1 , - 1 ):
1372- # ``Delete'' chars[i], and subtract count
1373- # (since redoing expandtabs is O(n))
1374- ncharsdeleted += 1
1375- if chars [i ] == '\t ' :
1376- have -= tabwidth
1377- else :
1378- have -= 1
1379- if have <= want or chars [i - 1 ] not in " \t " :
1380- break
1381- chars = chars [:len (chars ) - ncharsdeleted ]
1386+ ncharsdeleted , chars = TestWindow .delete_trail_whitespace (want , chars , tabwidth )
13821387 text .undo_block_start ()
13831388 text .delete ("insert-%dc" % ncharsdeleted , "insert" )
13841389 if have < want :
0 commit comments