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

Code before:
        let contents = doc.text();
        let selection = doc.selection(view.id).clone();
        let mut ranges = SmallVec::with_capacity(selection.len());

        // TODO: this is annoying, but we need to do it to properly calculate pos after edits
        let mut global_offs = 0;

        let mut transaction = Transaction::change_by_selection(contents, &selection, |range| {
            let pos = range.cursor(text);

            let prev = if pos == 0 {
                ' '
            } else {
                contents.char(pos - 1)
            };
            let curr = contents.get_char(pos).unwrap_or(' ');

            let current_line = text.char_to_line(pos);
            let line_is_only_whitespace = text
                .line(current_line)
                .chars()
                .all(|char| char.is_ascii_whitespace());

            let mut new_text = String::new();

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

                get_comment_token(doc.text(), tokens, current_line)
            };

            // If the current line is all whitespace, insert a line ending at the beginning of
            // the current line. This makes the current line empty and the new line contain the
            // indentation of the old line.
            let (from, to, local_offs) = if line_is_only_whitespace {
                let line_start = text.line_to_char(current_line);
                new_text.push_str(doc.line_ending.as_str());

                (line_start, line_start, new_text.chars().count())
            } else {
                let new_line_will_be_comment = config.continue_comments && comment_token.is_some();
                let line = text.line(current_line);

                let indent = 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,

Review comment (suggestion):
Similar here

```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, current_line))
} else {
    None
};
```

Code after:
            let pos = range.cursor(text);

            let prev = if pos == 0 {
                ' '
            } else {
                contents.char(pos - 1)
            };
            let curr = contents.get_char(pos).unwrap_or(' ');

            let current_line = text.char_to_line(pos);
            let line_is_only_whitespace = text
                .line(current_line)
                .chars()
                .all(|char| char.is_ascii_whitespace());

            let mut new_text = String::new();

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

            // If the current line is all whitespace, insert a line ending at the beginning of
            // the current line. This makes the current line empty and the new line contain the
            // indentation of the old line.
            let (from, to, local_offs) = if line_is_only_whitespace {
                let line_start = text.line_to_char(current_line);
                new_text.push_str(doc.line_ending.as_str());

                (line_start, line_start, new_text.chars().count())
            } else {
                let line = text.line(current_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,
                        current_line,
                        pos,
                        current_line,
                    ),
                };

                // If we are between pairs (such as brackets), we want to
                // insert an additional line which is indented one level
                // more and place the cursor there