def must_comment(view, region): non_whitespace_pos = search_non_whitespace(view, region, stop_on_line_feed=False) # The entire line is blank, a comment must be inserted in the region. if is_whitespace(view, non_whitespace_pos): return True # If it is the JSX open brace, we just need to check the next character. if is_jsx_open_brace(view, non_whitespace_pos): non_whitespace_pos += 1 # If the cursor is at a comment, it means that the user wants to remove it. return not is_comment(view, non_whitespace_pos)
def must_comment(view, region): """ Returns true if the region must be commented or not. """ non_whitespace_pos = search_non_whitespace( view, region, stop_on_line_feed=False ) # The entire line is blank, a comment must be inserted in the region. if is_whitespace(view, non_whitespace_pos): return True # If it is the JSX open brace, we just need to check the next character. if is_jsx_open_brace(view, non_whitespace_pos): non_whitespace_pos += 1 # If the cursor is at a comment, it means that the user wants to remove it. return not is_comment(view, non_whitespace_pos)
def comment_lines(view, edit, region): lines = view.lines(region) # Calculate the margin. margin = sys.maxsize for line in lines: non_whitespace_pos = search_non_whitespace(view, line) line_begin = line.begin() margin = min( non_whitespace_pos - line_begin, margin ) # Analyse the type of comment that must be used for the entire block. first_line = lines[0] comment_type = resolve_required_comment_type(view, first_line.begin()) # Comment. for line in reversed(lines): begin = line.begin() + margin end = max(line.end(), begin) empty_line = False # Added to ensure that the cursor won’t be moved after the comment. if begin == end: view.replace(edit, Region(end), '!') empty_line = True if comment_type == 'jsx': # JSX comment. if empty_line: view.insert(edit, end + 1, ' */}') view.erase(edit, Region(end, end + 1)) else: view.insert(edit, end, ' */}') view.insert(edit, begin, "{/* ") else: # Normal JS comment. view.insert(edit, begin, "// ") if empty_line: view.erase(edit, Region(begin + 3, begin + 4))
def comment_lines(view, edit, region): lines = view.lines(region) # Calculate the margin. margin = sys.maxsize for line in lines: non_whitespace_pos = search_non_whitespace(view, line) line_begin = line.begin() margin = min(non_whitespace_pos - line_begin, margin) # Analyse the type of comment that must be used for the entire block. first_line = lines[0] comment_type = resolve_required_comment_type(view, first_line.begin()) # Comment. for line in reversed(lines): begin = line.begin() + margin end = max(line.end(), begin) empty_line = False # Added to ensure that the cursor won’t be moved after the comment. if begin == end: view.replace(edit, Region(end), '!') empty_line = True if comment_type == 'jsx': # JSX comment. if empty_line: view.insert(edit, end + 1, ' */}') view.erase(edit, Region(end, end + 1)) else: view.insert(edit, end, ' */}') view.insert(edit, begin, "{/* ") else: # Normal JS comment. view.insert(edit, begin, "// ") if empty_line: view.erase(edit, Region(begin + 3, begin + 4))