(original) (raw)
changeset: 102445:128ad410c776 user: Terry Jan Reedy tjreedy@udel.edu date: Sun Jul 24 23:01:28 2016 -0400 files: Lib/idlelib/autocomplete.py Lib/idlelib/autocomplete_w.py Lib/idlelib/idle_test/test_autocomplete.py description: Issue #19198: IDLE: tab after initial whitespace should tab, not autocomplete. Fixes problem with writing docstrings at lease twice indented. diff -r ab28676df655 -r 128ad410c776 Lib/idlelib/autocomplete.py --- a/Lib/idlelib/autocomplete.py Mon Jul 25 02:21:14 2016 +0000 +++ b/Lib/idlelib/autocomplete.py Sun Jul 24 23:01:28 2016 -0400 @@ -78,16 +78,17 @@ open a completion list after that (if there is more than one completion) """ - if hasattr(event, "mc_state") and event.mc_state: - # A modifier was pressed along with the tab, continue as usual. + if hasattr(event, "mc_state") and event.mc_state or\ + not self.text.get("insert linestart", "insert").strip(): + # A modifier was pressed along with the tab or + # there is only previous whitespace on this line, so tab. return None if self.autocompletewindow and self.autocompletewindow.is_active(): self.autocompletewindow.complete() return "break" else: opened = self.open_completions(False, True, True) - if opened: - return "break" + return "break" if opened else None def _open_completions_later(self, *args): self._delayed_completion_index = self.text.index("insert") diff -r ab28676df655 -r 128ad410c776 Lib/idlelib/autocomplete_w.py --- a/Lib/idlelib/autocomplete_w.py Mon Jul 25 02:21:14 2016 +0000 +++ b/Lib/idlelib/autocomplete_w.py Sun Jul 24 23:01:28 2016 -0400 @@ -240,9 +240,8 @@ acw.wm_geometry("+%d+%d" % (new_x, new_y)) def hide_event(self, event): - if not self.is_active(): - return - self.hide_window() + if self.is_active(): + self.hide_window() def listselect_event(self, event): if self.is_active(): diff -r ab28676df655 -r 128ad410c776 Lib/idlelib/idle_test/test_autocomplete.py --- a/Lib/idlelib/idle_test/test_autocomplete.py Mon Jul 25 02:21:14 2016 +0000 +++ b/Lib/idlelib/idle_test/test_autocomplete.py Sun Jul 24 23:01:28 2016 -0400 @@ -97,6 +97,11 @@ self.assertIsNone(autocomplete.autocomplete_event(ev)) del ev.mc_state + # Test that tab after whitespace is ignored. + self.text.insert('1.0', ' """Docstring.\n ') + self.assertIsNone(autocomplete.autocomplete_event(ev)) + self.text.delete('1.0', 'end') + # If autocomplete window is open, complete() method is called self.text.insert('1.0', 're.') # This must call autocomplete._make_autocomplete_window() /tjreedy@udel.edu