aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorJaakko Paju2024-03-23 06:25:08 +0000
committerGitHub2024-03-23 06:25:08 +0000
commitd5c2973cd10c38512f6e568f097bedca46ff5f48 (patch)
tree2764d4aa99f46034b2e4ed7c9bdd7e8807e9481b /helix-term/src/commands.rs
parentbe307a420480178c1bc443992c8336f6471b8b7b (diff)
Fix repeat last motion for goto next/prev diagnostic (#9966)
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs71
1 files changed, 39 insertions, 32 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index a5e79a53..291ab1fe 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -3439,48 +3439,55 @@ fn goto_last_diag(cx: &mut Context) {
}
fn goto_next_diag(cx: &mut Context) {
- let (view, doc) = current!(cx.editor);
+ let motion = move |editor: &mut Editor| {
+ let (view, doc) = current!(editor);
- let cursor_pos = doc
- .selection(view.id)
- .primary()
- .cursor(doc.text().slice(..));
+ let cursor_pos = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
- let diag = doc
- .diagnostics()
- .iter()
- .find(|diag| diag.range.start > cursor_pos)
- .or_else(|| doc.diagnostics().first());
+ let diag = doc
+ .diagnostics()
+ .iter()
+ .find(|diag| diag.range.start > cursor_pos)
+ .or_else(|| doc.diagnostics().first());
- let selection = match diag {
- Some(diag) => Selection::single(diag.range.start, diag.range.end),
- None => return,
+ let selection = match diag {
+ Some(diag) => Selection::single(diag.range.start, diag.range.end),
+ None => return,
+ };
+ doc.set_selection(view.id, selection);
};
- doc.set_selection(view.id, selection);
+
+ cx.editor.apply_motion(motion);
}
fn goto_prev_diag(cx: &mut Context) {
- let (view, doc) = current!(cx.editor);
+ let motion = move |editor: &mut Editor| {
+ let (view, doc) = current!(editor);
- let cursor_pos = doc
- .selection(view.id)
- .primary()
- .cursor(doc.text().slice(..));
+ let cursor_pos = doc
+ .selection(view.id)
+ .primary()
+ .cursor(doc.text().slice(..));
- let diag = doc
- .diagnostics()
- .iter()
- .rev()
- .find(|diag| diag.range.start < cursor_pos)
- .or_else(|| doc.diagnostics().last());
-
- let selection = match diag {
- // NOTE: the selection is reversed because we're jumping to the
- // previous diagnostic.
- Some(diag) => Selection::single(diag.range.end, diag.range.start),
- None => return,
+ let diag = doc
+ .diagnostics()
+ .iter()
+ .rev()
+ .find(|diag| diag.range.start < cursor_pos)
+ .or_else(|| doc.diagnostics().last());
+
+ let selection = match diag {
+ // NOTE: the selection is reversed because we're jumping to the
+ // previous diagnostic.
+ Some(diag) => Selection::single(diag.range.end, diag.range.start),
+ None => return,
+ };
+ doc.set_selection(view.id, selection);
};
- doc.set_selection(view.id, selection);
+ cx.editor.apply_motion(motion)
}
fn goto_first_change(cx: &mut Context) {