on master help sign in
Add extend_to_first_nonwhitespace (#6837)

Closes #6836

commit096ed0ced449ff0355fed6220c762c4f7f28ec25 authorDimitri Sabadie <dimitri.sabadie@gmail.com> dateTue 25 Apr 2023, 13:14 (4 years ago) parent0097e19
1 file changed+20−1
helix-term/src/commands.rs+20−1
helix-term/src/commands.rs+20−1
@@ -347,6 +347,7 @@ impl MappableCommand {
347347 goto_first_nonwhitespace, "Goto first non-blank in line",
348348 trim_selections, "Trim whitespace from selections",
349349 extend_to_line_start, "Extend to line start",
350+ extend_to_first_nonwhitespace, "Extend to first non-blank in line",
350351 extend_to_line_end, "Extend to line end",
351352 extend_to_line_end_newline, "Extend to line end",
352353 signature_help, "Show signature help",
@@ -839,6 +840,24 @@ fn kill_to_line_end(cx: &mut Context) {
839840
840841fn goto_first_nonwhitespace(cx: &mut Context) {
841842 let (view, doc) = current!(cx.editor);
843+
844+ goto_first_nonwhitespace_impl(
845+ view,
846+ doc,
847+ if cx.editor.mode == Mode::Select {
848+ Movement::Extend
849+ } else {
850+ Movement::Move
851+ },
852+ )
853+}
854+
855+fn extend_to_first_nonwhitespace(cx: &mut Context) {
856+ let (view, doc) = current!(cx.editor);
857+ goto_first_nonwhitespace_impl(view, doc, Movement::Extend)
858+}
859+
860+fn goto_first_nonwhitespace_impl(view: &mut View, doc: &mut Document, movement: Movement) {
842861 let text = doc.text().slice(..);
843862
844863 let selection = doc.selection(view.id).clone().transform(|range| {
@@ -846,7 +865,7 @@ fn goto_first_nonwhitespace(cx: &mut Context) {
846865
847866 if let Some(pos) = find_first_non_whitespace_char(text.line(line)) {
848867 let pos = pos + text.line_to_char(line);
849− range.put_cursor(text, pos, cx.editor.mode == Mode::Select)
868+ range.put_cursor(text, pos, movement == Movement::Extend)
850869 } else {
851870 range
852871 }