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

Code before:
            (0, 0)
        } else {
            (
                line_end_char_index(&text, line_num),
                doc.line_ending.len_chars(),
            )
        };

        let indent = 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(comment_token) = has_line_comment(&config, doc, line_num) {
            text.push_str(&comment_token);
            text.push(' ');
        }

        let text = text.repeat(count);

        // calculate new selection ranges
        let pos = offs + line_end_index + line_end_offset_width;
        for i in 0..count {
            // pos                    -> beginning of reference line,
            // + (i * (1+indent_len)) -> beginning of i'th line from pos
            // + indent_len ->        -> indent for i'th line
            ranges.push(Range::point(pos + (i * (1 + indent_len)) + indent_len));
        }

        offs += text.chars().count();

        (line_end_index, line_end_index, Some(text.into()))
    });

    transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));

    doc.apply(&transaction, view.id);

    // Since we might have added a comment token, move to the end of the line.

Review comment (suggestion):
Comments often have an indentation that does not match its tree sitter indentation. 
I believe in the continue comments should copy the indentation of the previous line instead instead of using our indent system

Code after:
                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
        let pos = offs + line_end_index + line_end_offset_width;
        let comment_len = continue_comment_token
            .map(|token| token.len() + 1) // `+ 1` for the extra space added
            .unwrap_or_default();
        for i in 0..count {
            // pos                    -> beginning of reference line,
            // + (i * (1+indent_len + comment_len)) -> beginning of i'th line from pos (possibly including comment token)
            // + indent_len + comment_len ->        -> indent for i'th line
            ranges.push(Range::point(
                pos + (i * (1 + indent_len + comment_len)) + indent_len + comment_len,
            ));
        }