diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2016-07-25 03:01:28 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2016-07-25 03:01:28 (GMT) |
commit | c665dfd73e330213008f6422c25b5a115a541776 (patch) | |
tree | 42b888927fcfda7b7bc7241388c1f54012bfe4d8 /Lib/idlelib | |
parent | 996d72bccf2bc6d7d0be2ae1280186e68a0a1663 (diff) | |
download | cpython-c665dfd73e330213008f6422c25b5a115a541776.zip cpython-c665dfd73e330213008f6422c25b5a115a541776.tar.gz cpython-c665dfd73e330213008f6422c25b5a115a541776.tar.bz2 |
Issue #19198: IDLE: tab after initial whitespace should tab, not autocomplete.
Fixes problem with writing docstrings at lease twice indented.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r-- | Lib/idlelib/autocomplete.py | 9 | ||||
-rw-r--r-- | Lib/idlelib/autocomplete_w.py | 5 | ||||
-rw-r--r-- | Lib/idlelib/idle_test/test_autocomplete.py | 5 |
3 files changed, 12 insertions, 7 deletions
diff --git a/Lib/idlelib/autocomplete.py b/Lib/idlelib/autocomplete.py index 1c0b12d..1200008 100644 --- a/Lib/idlelib/autocomplete.py +++ b/Lib/idlelib/autocomplete.py @@ -78,16 +78,17 @@ class AutoComplete: 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 --git a/Lib/idlelib/autocomplete_w.py b/Lib/idlelib/autocomplete_w.py index 37d8928..31837e0 100644 --- a/Lib/idlelib/autocomplete_w.py +++ b/Lib/idlelib/autocomplete_w.py @@ -240,9 +240,8 @@ class AutoCompleteWindow: 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 --git a/Lib/idlelib/idle_test/test_autocomplete.py b/Lib/idlelib/idle_test/test_autocomplete.py index a14c6db..97bfab5 100644 --- a/Lib/idlelib/idle_test/test_autocomplete.py +++ b/Lib/idlelib/idle_test/test_autocomplete.py @@ -97,6 +97,11 @@ class AutoCompleteTest(unittest.TestCase): 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() |