diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index b02a9880505..c6aa00d0d54 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -3,6 +3,10 @@ Released on 2020-10-05? ====================================== +bpo-38636: Fix IDLE Format menu tab toggle and file indent width. These +functions (default shortcuts Alt-T and Alt-U) were mistakenly disabled +in 3.7.5 and 3.8.0. + bpo-4360: Add an option to toggle IDLE's cursor blink for shell, editor, and output windows. See Settings, General, Window Preferences, Cursor Blink. Patch by Zachary Spytz. diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index dff104ff0f1..92dcf57c4ff 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -186,8 +186,9 @@ class EditorWindow(object): text.bind("<>", fregion.uncomment_region_event) text.bind("<>", fregion.tabify_region_event) text.bind("<>", fregion.untabify_region_event) - text.bind("<>", self.Indents.toggle_tabs_event) - text.bind("<>", self.Indents.change_indentwidth_event) + indents = self.Indents(self) + text.bind("<>", indents.toggle_tabs_event) + text.bind("<>", indents.change_indentwidth_event) text.bind("", self.move_at_edge_if_selection(0)) text.bind("", self.move_at_edge_if_selection(1)) text.bind("<>", self.del_word_left) diff --git a/Lib/idlelib/format.py b/Lib/idlelib/format.py index bced4c1770e..2b098056573 100644 --- a/Lib/idlelib/format.py +++ b/Lib/idlelib/format.py @@ -353,8 +353,7 @@ class FormatRegion: maxvalue=16) -# With mixed indents not allowed, these are semi-useless and not unittested. -class Indents: # pragma: no cover +class Indents: "Change future indents." def __init__(self, editwin): diff --git a/Lib/idlelib/idle_test/test_format.py b/Lib/idlelib/idle_test/test_format.py index c7b123e9d51..20b5970f498 100644 --- a/Lib/idlelib/idle_test/test_format.py +++ b/Lib/idlelib/idle_test/test_format.py @@ -417,7 +417,7 @@ class FormatRegionTest(unittest.TestCase): self.text.delete('1.0', 'end') code_sample = """\ - +# WS line needed for test. class C1(): # Class comment. def __init__(self, a, b): @@ -574,7 +574,42 @@ class C1(): self.assertEqual(ask(), 10) -class rstripTest(unittest.TestCase): +class IndentsTest(unittest.TestCase): + + @mock.patch.object(ft, "askyesno") + def test_toggle_tabs(self, askyesno): + editor = DummyEditwin(None, None) # usetabs == False. + indents = ft.Indents(editor) + askyesno.return_value = True + + indents.toggle_tabs_event(None) + self.assertEqual(editor.usetabs, True) + self.assertEqual(editor.indentwidth, 8) + + indents.toggle_tabs_event(None) + self.assertEqual(editor.usetabs, False) + self.assertEqual(editor.indentwidth, 8) + + @mock.patch.object(ft, "askinteger") + def test_change_indentwidth(self, askinteger): + editor = DummyEditwin(None, None) # indentwidth == 4. + indents = ft.Indents(editor) + + askinteger.return_value = None + indents.change_indentwidth_event(None) + self.assertEqual(editor.indentwidth, 4) + + askinteger.return_value = 3 + indents.change_indentwidth_event(None) + self.assertEqual(editor.indentwidth, 3) + + askinteger.return_value = 5 + editor.usetabs = True + indents.change_indentwidth_event(None) + self.assertEqual(editor.indentwidth, 3) + + +class RstripTest(unittest.TestCase): def test_rstrip_line(self): editor = MockEditor() diff --git a/Misc/NEWS.d/next/IDLE/2019-10-30-22-11-16.bpo-38636.hUhDeB.rst b/Misc/NEWS.d/next/IDLE/2019-10-30-22-11-16.bpo-38636.hUhDeB.rst new file mode 100644 index 00000000000..4262dbea6d8 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2019-10-30-22-11-16.bpo-38636.hUhDeB.rst @@ -0,0 +1,3 @@ +Fix IDLE Format menu tab toggle and file indent width. These functions +(default shortcuts Alt-T and Alt-U) were mistakenly disabled in 3.7.5 +and 3.8.0.