Skip to content

Commit

Permalink
Add new command to cycle through version control conflict markers
Browse files Browse the repository at this point in the history
Issue: #4647
  • Loading branch information
wes adams committed Nov 11, 2022
1 parent d7be546 commit 0863ff8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 4 additions & 2 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,10 @@ Mappings in the style of [vim-unimpaired](https://github.com/tpope/vim-unimpaire
| `]t` | Go to previous test (**TS**) | `goto_prev_test` |
| `]p` | Go to next paragraph | `goto_next_paragraph` |
| `[p` | Go to previous paragraph | `goto_prev_paragraph` |
| `[Space` | Add newline above | `add_newline_above` |
| `]Space` | Add newline below | `add_newline_below` |
| `]n` | Go to next source control conflict marker | `goto_next_conflict_marker` |
| `[n` | Go to previous source control conflict marker| `goto_prev_conflict_marker` |
| `[Space` | Add newline above | `add_newline_above` |
| `]Space` | Add newline below | `add_newline_below` |

## Insert mode

Expand Down
29 changes: 29 additions & 0 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -984,6 +986,33 @@ 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();
let config = cx.editor.config();
let scrolloff = config.scrolloff;
let wrap_around = config.search.wrap_around;
search_impl(
cx.editor,
&contents,
&re,
movement,
direction,
scrolloff,
wrap_around,
false,
);
}

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);
Expand Down
2 changes: 2 additions & 0 deletions helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"o" => goto_prev_comment,
"t" => goto_prev_test,
"p" => goto_prev_paragraph,
"n" => goto_prev_conflict_marker,
"space" => add_newline_above,
},
"]" => { "Right bracket"
Expand All @@ -117,6 +118,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"o" => goto_next_comment,
"t" => goto_next_test,
"p" => goto_next_paragraph,
"n" => goto_next_conflict_marker,
"space" => add_newline_below,
},

Expand Down

0 comments on commit 0863ff8

Please sign in to comment.