Skip to content

Commit e396482

Browse files
miss-islingtonserhiy-storchakaserwyclaude
authored
[3.13] gh-60402: Fix Tab in a string in IDLE (GH-157593) (#157632)
gh-60402: Fix Tab in a string in IDLE (GH-157593) Open the file name completion list only if some file name starts with the text before the cursor; otherwise insert a tab. If one wants the completion list, use Edit => Show completions. (cherry picked from commit 699e802) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Roger Serwy <roger.serwy@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 36dbdc2 commit e396482

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/idlelib/autocomplete.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ def open_completions(self, args):
153153
comp_lists = self.fetch_completions(comp_what, mode)
154154
if not comp_lists[0]:
155155
return None
156+
if (complete and mode == FILES
157+
and not any(name.startswith(comp_start)
158+
for name in comp_lists[0])):
159+
return None
156160
self.autocompletewindow = self._make_autocomplete_window()
157161
return not self.autocompletewindow.show_window(
158162
comp_lists, "insert-%dc" % len(comp_start),

Lib/idlelib/idle_test/test_autocomplete.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ def make_acw(): return self.dummy_acw()
218218
self.assertTrue(acp.open_completions(ac.TAB))
219219
self.text.delete('1.0', 'end')
220220

221+
# No file name starts with the text (gh-60402).
222+
self.text.insert('1.0', '"hello wor')
223+
self.assertIsNone(acp.open_completions(ac.TAB))
224+
self.assertTrue(acp.open_completions(ac.FORCE))
225+
self.text.delete('1.0', 'end')
226+
221227
def test_completion_kwds(self):
222228
self.assertIn('and', ac.completion_kwds)
223229
self.assertIn('case', ac.completion_kwds)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In IDLE, Tab in a string that is not the start of a file name inserts a tab
2+
instead of opening the completion list.

0 commit comments

Comments
 (0)