Select diagnostic range in goto_*_diag commands (#4713)
This roughly matches the behavior of the diagnostic picker: when jumping to a diagnostic with `[d`/`]d`/`[D`/`]D`, the range of the diagnostic is selected instead of the start point.
This commit is contained in:
parent
2a60de74f9
commit
42ad1a9e04
1 changed files with 24 additions and 30 deletions
|
@ -2789,35 +2789,28 @@ fn exit_select_mode(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_pos(editor: &mut Editor, pos: usize) {
|
fn goto_first_diag(cx: &mut Context) {
|
||||||
let (view, doc) = current!(editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
|
let selection = match doc.diagnostics().first() {
|
||||||
push_jump(view, doc);
|
Some(diag) => Selection::single(diag.range.start, diag.range.end),
|
||||||
doc.set_selection(view.id, Selection::point(pos));
|
None => return,
|
||||||
|
};
|
||||||
|
doc.set_selection(view.id, selection);
|
||||||
align_view(doc, view, Align::Center);
|
align_view(doc, view, Align::Center);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_first_diag(cx: &mut Context) {
|
|
||||||
let doc = doc!(cx.editor);
|
|
||||||
let pos = match doc.diagnostics().first() {
|
|
||||||
Some(diag) => diag.range.start,
|
|
||||||
None => return,
|
|
||||||
};
|
|
||||||
goto_pos(cx.editor, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn goto_last_diag(cx: &mut Context) {
|
fn goto_last_diag(cx: &mut Context) {
|
||||||
let doc = doc!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let pos = match doc.diagnostics().last() {
|
let selection = match doc.diagnostics().last() {
|
||||||
Some(diag) => diag.range.start,
|
Some(diag) => Selection::single(diag.range.start, diag.range.end),
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
goto_pos(cx.editor, pos);
|
doc.set_selection(view.id, selection);
|
||||||
|
align_view(doc, view, Align::Center);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_next_diag(cx: &mut Context) {
|
fn goto_next_diag(cx: &mut Context) {
|
||||||
let editor = &mut cx.editor;
|
let (view, doc) = current!(cx.editor);
|
||||||
let (view, doc) = current!(editor);
|
|
||||||
|
|
||||||
let cursor_pos = doc
|
let cursor_pos = doc
|
||||||
.selection(view.id)
|
.selection(view.id)
|
||||||
|
@ -2830,17 +2823,16 @@ fn goto_next_diag(cx: &mut Context) {
|
||||||
.find(|diag| diag.range.start > cursor_pos)
|
.find(|diag| diag.range.start > cursor_pos)
|
||||||
.or_else(|| doc.diagnostics().first());
|
.or_else(|| doc.diagnostics().first());
|
||||||
|
|
||||||
let pos = match diag {
|
let selection = match diag {
|
||||||
Some(diag) => diag.range.start,
|
Some(diag) => Selection::single(diag.range.start, diag.range.end),
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
doc.set_selection(view.id, selection);
|
||||||
goto_pos(editor, pos);
|
align_view(doc, view, Align::Center);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_prev_diag(cx: &mut Context) {
|
fn goto_prev_diag(cx: &mut Context) {
|
||||||
let editor = &mut cx.editor;
|
let (view, doc) = current!(cx.editor);
|
||||||
let (view, doc) = current!(editor);
|
|
||||||
|
|
||||||
let cursor_pos = doc
|
let cursor_pos = doc
|
||||||
.selection(view.id)
|
.selection(view.id)
|
||||||
|
@ -2854,12 +2846,14 @@ fn goto_prev_diag(cx: &mut Context) {
|
||||||
.find(|diag| diag.range.start < cursor_pos)
|
.find(|diag| diag.range.start < cursor_pos)
|
||||||
.or_else(|| doc.diagnostics().last());
|
.or_else(|| doc.diagnostics().last());
|
||||||
|
|
||||||
let pos = match diag {
|
let selection = match diag {
|
||||||
Some(diag) => diag.range.start,
|
// 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,
|
None => return,
|
||||||
};
|
};
|
||||||
|
doc.set_selection(view.id, selection);
|
||||||
goto_pos(editor, pos);
|
align_view(doc, view, Align::Center);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto_first_change(cx: &mut Context) {
|
fn goto_first_change(cx: &mut Context) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue