Skip to content

Commit 6604a73

Browse files
committed
fix everythign
1 parent a087395 commit 6604a73

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

Lib/idlelib/editor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ def delete_trail_char_and_space(self, want, chars, tabwidth):
13541354
if chars[i] not in " \t":
13551355
ncharsretained = i + 1
13561356
chars = chars[:ncharsretained]
1357-
return len(chars) - ncharsretained + 1, chars # removal of last
1357+
return chars
13581358

13591359
def smart_backspace_event(self, event):
13601360
text = self.text
@@ -1384,7 +1384,9 @@ def smart_backspace_event(self, event):
13841384
assert have > 0
13851385
want = ((have - 1) // self.indentwidth) * self.indentwidth
13861386
# Debug prompt is multilined....
1387-
ncharsdeleted, chars = self.delete_trail_char_and_space(want, chars, tabwidth)
1387+
oldchars = chars
1388+
chars = self.delete_trail_char_and_space(want, chars, tabwidth)
1389+
ncharsdeleted = len(oldchars) - len(chars)
13881390
have = len(chars.expandtabs(tabwidth))
13891391
text.undo_block_start()
13901392
text.delete("insert-%dc" % ncharsdeleted, "insert")

Lib/idlelib/idle_test/test_editor.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,8 @@ class DeleteWantTest(unittest.TestCase):
260260
(13, 4, "abcde\tabd\t "),
261261
(16, 4, "abcde\tabd\t \t"),
262262
]),
263-
("\tabcd", [
264-
(2, 4, ""),
265-
(5, 4, "\ta"),
263+
(" ", [
264+
(2, 2, " "),
266265
]),
267266
]
268267

@@ -274,30 +273,27 @@ def mock_delete_trail_char_and_space(self, want, chars, tabwidth):
274273
have = len(chars.expandtabs(tabwidth))
275274
if have <= want or chars[-1] not in " \t":
276275
break
277-
return ncharsdeleted, chars
276+
return chars
277+
278+
def do_tests(self):
279+
ew = Editor()
280+
for dat in self.data:
281+
test_str = dat[0]
282+
for da in dat[1]:
283+
with self.subTest(want=da[0], tabwidth=da[1], input=test_str):
284+
res = ew.delete_trail_char_and_space(da[0], test_str, da[1])
285+
self.assertEqual(res, da[2])
278286

279287
def test_delete_trail_char_and_space(self):
280-
with unittest.mock.patch.object(Editor, '__init__', return_value=None) as mock_init:
288+
with unittest.mock.patch.object(Editor, '__init__', return_value=None):
281289
initial_time_new = time.time()
282-
ew = Editor()
283-
for dat in self.data:
284-
test_str = dat[0]
285-
for da in dat[1]:
286-
with self.subTest(want=da[0], tabwidth=da[1], input=test_str):
287-
res_str = ew.delete_trail_char_and_space(da[0], test_str, da[1])[1]
288-
self.assertEqual(res_str, da[2])
290+
self.do_tests()
289291
time_new = time.time() - initial_time_new
290-
291-
initial_time_old = time.time()
292+
292293
with unittest.mock.patch.object(Editor, 'delete_trail_char_and_space', self.mock_delete_trail_char_and_space):
293-
ew = Editor()
294-
for dat in self.data:
295-
test_str = dat[0]
296-
for da in dat[1]:
297-
with self.subTest(want=da[0], tabwidth=da[1], input=test_str):
298-
res_str = ew.delete_trail_char_and_space(da[0], test_str, da[1])[1]
299-
self.assertEqual(res_str, da[2])
300-
time_old = time.time() - initial_time_old
294+
initial_time_old = time.time()
295+
self.do_tests()
296+
time_old = time.time() - initial_time_old
301297

302298
self.assertGreaterEqual(time_old / time_new, 10)
303299

0 commit comments

Comments
 (0)