on master help sign in
Select diagnostic range in goto_*_diag commands (#4713)
42ad1a9Michael Davis
helix-term/src/commands.rs+22−28
@@ -2789,35 +2789,28 @@ fn exit_select_mode(cx: &mut Context) {
2789 }
2789 }
2790}
2790}
2791
2791
2792−fn goto_pos(editor: &mut Editor, pos: usize) {
2793− let (view, doc) = current!(editor);
2794−
2795− push_jump(view, doc);
2796− doc.set_selection(view.id, Selection::point(pos));
2797− align_view(doc, view, Align::Center);
2798−}
2799−
2800fn goto_first_diag(cx: &mut Context) {
2792fn goto_first_diag(cx: &mut Context) {
2801− let doc = doc!(cx.editor);
2793+ let (view, doc) = current!(cx.editor);
2802− let pos = match doc.diagnostics().first() {
2794+ let selection = match doc.diagnostics().first() {
2803− Some(diag) => diag.range.start,
2795+ Some(diag) => Selection::single(diag.range.start, diag.range.end),
2804 None => return,
2796 None => return,
2805 };
2797 };
2806− goto_pos(cx.editor, pos);
2798+ doc.set_selection(view.id, selection);
2799+ align_view(doc, view, Align::Center);
2807}
2800}
2808
2801
2809fn goto_last_diag(cx: &mut Context) {
2802fn goto_last_diag(cx: &mut Context) {
2810− let doc = doc!(cx.editor);
2803+ let (view, doc) = current!(cx.editor);
2811− let pos = match doc.diagnostics().last() {
2804+ let selection = match doc.diagnostics().last() {
2812− Some(diag) => diag.range.start,
2805+ Some(diag) => Selection::single(diag.range.start, diag.range.end),
2813 None => return,
2806 None => return,
2814 };
2807 };
2815− goto_pos(cx.editor, pos);
2808+ doc.set_selection(view.id, selection);
2809+ align_view(doc, view, Align::Center);
2816}
2810}
2817
2811
2818fn goto_next_diag(cx: &mut Context) {
2812fn goto_next_diag(cx: &mut Context) {
2819− let editor = &mut cx.editor;
2820− let (view, doc) = current!(editor);
2813+ let (view, doc) = current!(cx.editor);
2821
2814
2822 let cursor_pos = doc
2815 let cursor_pos = doc
2823 .selection(view.id)
2816 .selection(view.id)
@@ -2830,17 +2823,16 @@ fn goto_next_diag(cx: &mut Context) {
2830 .find(|diag| diag.range.start > cursor_pos)
2823 .find(|diag| diag.range.start > cursor_pos)
2831 .or_else(|| doc.diagnostics().first());
2824 .or_else(|| doc.diagnostics().first());
2832
2825
2833− let pos = match diag {
2826+ let selection = match diag {
2834− Some(diag) => diag.range.start,
2827+ Some(diag) => Selection::single(diag.range.start, diag.range.end),
2835 None => return,
2828 None => return,
2836 };
2829 };
2837−
2830+ doc.set_selection(view.id, selection);
2838− goto_pos(editor, pos);
2831+ align_view(doc, view, Align::Center);
2839}
2832}
2840
2833
2841fn goto_prev_diag(cx: &mut Context) {
2834fn goto_prev_diag(cx: &mut Context) {
2842− let editor = &mut cx.editor;
2843− let (view, doc) = current!(editor);
2835+ let (view, doc) = current!(cx.editor);
2844
2836
2845 let cursor_pos = doc
2837 let cursor_pos = doc
2846 .selection(view.id)
2838 .selection(view.id)
@@ -2854,12 +2846,14 @@ fn goto_prev_diag(cx: &mut Context) {
2854 .find(|diag| diag.range.start < cursor_pos)
2846 .find(|diag| diag.range.start < cursor_pos)
2855 .or_else(|| doc.diagnostics().last());
2847 .or_else(|| doc.diagnostics().last());
2856
2848
2857− let pos = match diag {
2849+ let selection = match diag {
2850+ // NOTE: the selection is reversed because we're jumping to the
2851+ // previous diagnostic.
2858− Some(diag) => diag.range.start,
2852+ Some(diag) => Selection::single(diag.range.end, diag.range.start),
2859 None => return,
2853 None => return,
2860 };
2854 };
2861−
2855+ doc.set_selection(view.id, selection);
2862− goto_pos(editor, pos);
2856+ align_view(doc, view, Align::Center);
2863}
2857}
2864
2858
2865fn goto_first_change(cx: &mut Context) {
2859fn goto_first_change(cx: &mut Context) {