Repository: helix-editor/helix
File: helix-term/src/commands.rs (Rust)

Code before:
            Open::Below => cursor_line + 1,
            // adjust position to the end of the previous line (current line - 1)
            Open::Above => cursor_line,
        };

        let line_num = new_line.saturating_sub(1);

        // Index to insert newlines after, as well as the char width
        // to use to compensate for those inserted newlines.
        let (line_end_index, line_end_offset_width) = if new_line == 0 {
            (0, 0)
        } else {
            (
                line_end_char_index(&doc_text, line_num),
                doc.line_ending.len_chars(),
            )
        };

        let comment_token = {
            let tokens = doc
                .language_config()
                .and_then(|config| config.comment_tokens.as_ref());

            get_comment_token(doc.text(), tokens, cursor_line)
        };
        let new_line_will_be_comment = config.continue_comments && comment_token.is_some();

        let indent = {
            let line = doc_text.line(cursor_line);
            match line.first_non_whitespace_char() {
                Some(pos) if new_line_will_be_comment => line.slice(..pos).to_string(),
                _ => indent::indent_for_newline(
                    doc.language_config(),
                    doc.syntax(),
                    &doc.config.load().indent_heuristic,
                    &doc.indent_style,
                    doc.tab_width(),
                    doc_text,
                    line_num,
                    line_end_index,
                    cursor_line,
                ),
            }
        };

        let indent_len = indent.len();
        let mut text = String::with_capacity(1 + indent_len);
        text.push_str(doc.line_ending.as_str());
        text.push_str(&indent);

        if config.continue_comments {

Review comment (suggestion):
We can clean this up a bit to both signal that we will be continuing the comment and carry the comment token:

```rust
let continue_comment_token = if config.continue_comments {
    doc.language_config()
        .and_then(|config| config.comment_tokens.as_ref())
        .and_then(|tokens| comment::get_comment_token(text, tokens, cursor_line))
} else {
    None
};
```

then in the `match` below we check if `continue_comment_token.is_some()` instead

Code after:
            // adjust position to the end of the previous line (current line - 1)
            Open::Above => cursor_line,
        };

        let line_num = new_line.saturating_sub(1);

        // Index to insert newlines after, as well as the char width
        // to use to compensate for those inserted newlines.
        let (line_end_index, line_end_offset_width) = if new_line == 0 {
            (0, 0)
        } else {
            (
                line_end_char_index(&text, line_num),
                doc.line_ending.len_chars(),
            )
        };

        let continue_comment_token = doc
            .language_config()
            .and_then(|config| config.comment_tokens.as_ref())
            .and_then(|tokens| comment::get_comment_token(text, tokens, cursor_line));

        let line = text.line(cursor_line);
        let indent = match line.first_non_whitespace_char() {
            Some(pos) if continue_comment_token.is_some() => line.slice(..pos).to_string(),
            _ => indent::indent_for_newline(
                doc.language_config(),
                doc.syntax(),
                &doc.config.load().indent_heuristic,
                &doc.indent_style,
                doc.tab_width(),
                text,
                line_num,
                line_end_index,
                cursor_line,
            ),
        };

        let indent_len = indent.len();
        let mut text = String::with_capacity(1 + indent_len);
        text.push_str(doc.line_ending.as_str());
        text.push_str(&indent);

        if let Some(token) = continue_comment_token {
            text.push_str(token);
            text.push(' ');
        }

        let text = text.repeat(count);

        // calculate new selection ranges