MCPcopy Index your code
hub / github.com/python/cpython / squeeze_current_text

Method squeeze_current_text

Lib/idlelib/squeezer.py:290–335  ·  view source on GitHub ↗

Squeeze the text block where the insertion cursor is. If the cursor is not in a squeezable block of text, give the user a small warning and do nothing.

(self)

Source from the content-addressed store, hash-verified

288 return count_lines_with_wrapping(s, self.editwin.width)
289
290 def squeeze_current_text(self):
291 """Squeeze the text block where the insertion cursor is.
292
293 If the cursor is not in a squeezable block of text, give the
294 user a small warning and do nothing.
295 """
296 # Set tag_name to the first valid tag found on the "insert" cursor.
297 tag_names = self.text.tag_names(tk.INSERT)
298 for tag_name in ("stdout", "stderr"):
299 if tag_name in tag_names:
300 break
301 else:
302 # The insert cursor doesn't have a "stdout" or "stderr" tag.
303 self.text.bell()
304 return "break"
305
306 # Find the range to squeeze.
307 start, end = self.text.tag_prevrange(tag_name, tk.INSERT + "+1c")
308 s = self.text.get(start, end)
309
310 # If the last char is a newline, remove it from the range.
311 if len(s) > 0 and s[-1] == '\n':
312 end = self.text.index("%s-1c" % end)
313 s = s[:-1]
314
315 # Delete the text.
316 self.base_text.delete(start, end)
317
318 # Prepare an ExpandingButton.
319 numoflines = self.count_lines(s)
320 expandingbutton = ExpandingButton(s, tag_name, numoflines, self)
321
322 # insert the ExpandingButton to the Text
323 self.text.window_create(start, window=expandingbutton,
324 padx=3, pady=5)
325
326 # Insert the ExpandingButton to the list of ExpandingButtons,
327 # while keeping the list ordered according to the position of
328 # the buttons in the Text widget.
329 i = len(self.expandingbuttons)
330 while i > 0 and self.text.compare(self.expandingbuttons[i-1],
331 ">", expandingbutton):
332 i -= 1
333 self.expandingbuttons.insert(i, expandingbutton)
334
335 return "break"
336
337
338Squeezer.reload()

Calls 11

count_linesMethod · 0.95
ExpandingButtonClass · 0.85
tag_namesMethod · 0.80
tag_prevrangeMethod · 0.80
window_createMethod · 0.80
bellMethod · 0.45
getMethod · 0.45
indexMethod · 0.45
deleteMethod · 0.45
compareMethod · 0.45
insertMethod · 0.45