bpo-33610: IDLE's code-context always shows current context immediate… · python/cpython@db2957c

3 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -63,10 +63,13 @@ def __init__(self, editwin):

6363

"""

6464

self.editwin = editwin

6565

self.text = editwin.text

66+

self._reset()

67+
68+

def _reset(self):

6669

self.context = None

70+

self.t1 = None

6771

self.topvisible = 1

6872

self.info = [(0, -1, "", False)]

69-

self.t1 = None

7073
7174

@classmethod

7275

def reload(cls):

@@ -112,17 +115,17 @@ def toggle_code_context_event(self, event=None):

112115

padx=padx, border=border, relief=SUNKEN, state='disabled')

113116

self.update_highlight_colors()

114117

self.context.bind('<ButtonRelease-1>', self.jumptoline)

118+

# Get the current context and initiate the recurring update event.

119+

self.timer_event()

115120

# Pack the context widget before and above the text_frame widget,

116121

# thus ensuring that it will appear directly above text_frame.

117122

self.context.pack(side=TOP, fill=X, expand=False,

118123

before=self.editwin.text_frame)

119124

menu_status = 'Hide'

120-

self.t1 = self.text.after(self.UPDATEINTERVAL, self.timer_event)

121125

else:

122126

self.context.destroy()

123-

self.context = None

124127

self.text.after_cancel(self.t1)

125-

self.t1 = None

128+

self._reset()

126129

menu_status = 'Show'

127130

self.editwin.update_menu_label(menu='options', index='* Code Context',

128131

label=f'{menu_status} Code Context')

Original file line numberDiff line numberDiff line change

@@ -135,7 +135,7 @@ def test_toggle_code_context_event(self):

135135

toggle()

136136
137137

# Toggle on.

138-

eq(toggle(), 'break')

138+

toggle()

139139

self.assertIsNotNone(cc.context)

140140

eq(cc.context['font'], self.text['font'])

141141

eq(cc.context['fg'], self.highlight_cfg['foreground'])

@@ -145,11 +145,22 @@ def test_toggle_code_context_event(self):

145145

eq(self.root.tk.call('after', 'info', self.cc.t1)[1], 'timer')

146146
147147

# Toggle off.

148-

eq(toggle(), 'break')

148+

toggle()

149149

self.assertIsNone(cc.context)

150150

eq(cc.editwin.label, 'Show Code Context')

151151

self.assertIsNone(self.cc.t1)

152152
153+

# Scroll down and toggle back on.

154+

line11_context = '\n'.join(x[2] for x in cc.get_context(11)[0])

155+

cc.text.yview(11)

156+

toggle()

157+

eq(cc.context.get('1.0', 'end-1c'), line11_context)

158+
159+

# Toggle off and on again.

160+

toggle()

161+

toggle()

162+

eq(cc.context.get('1.0', 'end-1c'), line11_context)

163+
153164

def test_get_context(self):

154165

eq = self.assertEqual

155166

gc = self.cc.get_context

@@ -329,7 +340,7 @@ def test_font(self):

329340

eq = self.assertEqual

330341

cc = self.cc

331342

save_font = cc.text['font']

332-

test_font = 'TkFixedFont'

343+

test_font = 'TkTextFont'

333344
334345

# Ensure code context is not active.

335346

if cc.context is not None:

Original file line numberDiff line numberDiff line change

@@ -0,0 +1 @@

1+

Fix code context not showing the correct context when first toggled on.