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

Method get_region

Lib/idlelib/format.py:218–238  ·  view source on GitHub ↗

Return line information about the selected text region. If text is selected, the first and last indices will be for the selection. If there is no text selected, the indices will be the current cursor location. Return a tuple containing (first index, last index,

(self)

Source from the content-addressed store, hash-verified

216 self.editwin = editwin
217
218 def get_region(self):
219 """Return line information about the selected text region.
220
221 If text is selected, the first and last indices will be
222 for the selection. If there is no text selected, the
223 indices will be the current cursor location.
224
225 Return a tuple containing (first index, last index,
226 string representation of text, list of text lines).
227 """
228 text = self.editwin.text
229 first, last = self.editwin.get_selection_indices()
230 if first and last:
231 head = text.index(first + " linestart")
232 tail = text.index(last + "-1c lineend +1c")
233 else:
234 head = text.index("insert linestart")
235 tail = text.index("insert lineend +1c")
236 chars = text.get(head, tail)
237 lines = chars.split("\n")
238 return head, tail, chars, lines
239
240 def set_region(self, head, tail, chars, lines):
241 """Replace the text between the given indices.

Callers 8

indent_region_eventMethod · 0.95
dedent_region_eventMethod · 0.95
comment_region_eventMethod · 0.95
tabify_region_eventMethod · 0.95
untabify_region_eventMethod · 0.95
applyFunction · 0.80
test_set_regionMethod · 0.80

Calls 4

get_selection_indicesMethod · 0.45
indexMethod · 0.45
getMethod · 0.45
splitMethod · 0.45

Tested by 1

test_set_regionMethod · 0.64