def METHOD_NAME(text):
    if len(text.tag_ranges("sel")) > 0:
        lineno, col_offset = map(int, text.index(tk.SEL_FIRST).split("."))
        end_lineno, end_col_offset = map(int, text.index(tk.SEL_LAST).split("."))
        if end_lineno > lineno and end_col_offset == 0:
            # SelectAll includes nonexisting extra line
            end_lineno -= 1
            end_col_offset = int(text.index(str(end_lineno) + ".end").split(".")[1])
    else:
        lineno, col_offset = map(int, text.index(tk.INSERT).split("."))
        end_lineno, end_col_offset = lineno, col_offset
    return TextRange(lineno, col_offset, end_lineno, end_col_offset)