From 4d67be9efca3d9abc61805e9abab02670a7e57c3 Mon Sep 17 00:00:00 2001 From: wes adams Date: Wed, 9 Nov 2022 17:16:47 -0500 Subject: [PATCH] Add new command to cycle through version control conflict markers Issue: #4647 --- helix-term/src/commands.rs | 19 +++++++++++++++++++ helix-term/src/keymap/default.rs | 2 ++ 2 files changed, 21 insertions(+) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 7e4969c1a7fbd..31d76fd5ddb45 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -411,6 +411,8 @@ impl MappableCommand { goto_prev_test, "Goto previous test", goto_next_paragraph, "Goto next paragraph", goto_prev_paragraph, "Goto previous paragraph", + goto_next_conflict_marker, "Goto next conflict marker", + goto_prev_conflict_marker, "Goto prev conflict marker", dap_launch, "Launch debug target", dap_toggle_breakpoint, "Toggle breakpoint", dap_continue, "Continue program execution", @@ -984,6 +986,23 @@ fn goto_next_paragraph(cx: &mut Context) { goto_para_impl(cx, movement::move_next_paragraph) } +fn goto_conflict_marker(cx: &mut Context, movement: Movement, direction: Direction) { + let (_, doc) = current!(cx.editor); + let contents = doc.text().slice(..).to_string(); + let re = Regex::new("<<<<<<<|=======|>>>>>>>").unwrap(); + search_impl( + cx.editor, &contents, &re, movement, direction, 0, true, true, + ); +} + +fn goto_next_conflict_marker(cx: &mut Context) { + goto_conflict_marker(cx, Movement::Move, Direction::Forward) +} + +fn goto_prev_conflict_marker(cx: &mut Context) { + goto_conflict_marker(cx, Movement::Move, Direction::Backward) +} + fn goto_file_start(cx: &mut Context) { if cx.count.is_some() { goto_line(cx); diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 118764d975858..4ddc598a201fa 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -106,6 +106,7 @@ pub fn default() -> HashMap { "o" => goto_prev_comment, "t" => goto_prev_test, "p" => goto_prev_paragraph, + "n" => goto_prev_conflict_marker, "space" => add_newline_above, }, "]" => { "Right bracket" @@ -117,6 +118,7 @@ pub fn default() -> HashMap { "o" => goto_next_comment, "t" => goto_next_test, "p" => goto_next_paragraph, + "n" => goto_next_conflict_marker, "space" => add_newline_below, },