Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new command to cycle through version control conflict markers #4708

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ 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` |
| `]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` |

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