Skip to content

Commit

Permalink
fix insert_at_line_start
Browse files Browse the repository at this point in the history
  • Loading branch information
CptPotato committed May 7, 2023
1 parent 34f0956 commit 98bf2ab
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2720,22 +2720,23 @@ fn insert_at_line_start(cx: &mut Context) {
insert_with_indent(cx, |cursor_line, cursor_line_start, text| {
find_first_non_whitespace_char(text.line(cursor_line))
.map(|ws_offset| ws_offset + cursor_line_start)
.unwrap_or(cursor_line_start)
});
}

// A inserts at the end of each line with a selection
// If the line is empty, automatically indent
fn insert_at_line_end(cx: &mut Context) {
insert_with_indent(cx, |cursor_line, _, text| {
Some(line_end_char_index(text, cursor_line))
line_end_char_index(text, cursor_line)
});
}

// Enter insert mode and auto-indent the current line if it is empty.
// If the line is not empty, move the cursor to the specified fallback position.
fn insert_with_indent(
cx: &mut Context,
cursor_fallback: impl Fn(usize, usize, &RopeSlice) -> Option<usize>,
cursor_fallback: impl Fn(usize, usize, &RopeSlice) -> usize,
) {
enter_insert_mode(cx);

Expand Down Expand Up @@ -2780,10 +2781,8 @@ fn insert_with_indent(
(line_end_index, line_end_index, Some(indent.into()))
} else {
// move cursor to the fallback position
let range = cursor_fallback(cursor_line, cursor_line_start, &text)
.map(|pos| range.put_cursor(text, pos + offs, cx.editor.mode == Mode::Select))
.unwrap_or(*range);
ranges.push(range);
let pos = cursor_fallback(cursor_line, cursor_line_start, &text);
ranges.push(range.put_cursor(text, pos + offs, cx.editor.mode == Mode::Select));

(cursor_line_start, cursor_line_start, None)
}
Expand Down

0 comments on commit 98bf2ab

Please sign in to comment.