@@ -2927,14 +2927,6 @@ fn exit_select_mode(cx: &mut Context) {
2930−fn goto_pos(editor: &mut Editor, pos: usize) {
2931− let (view, doc) = current!(editor);
2933− push_jump(view, doc);
2934− doc.set_selection(view.id, Selection::point(pos));
2935− align_view(doc, view, Align::Center);
2938fn goto_first_diag(cx: &mut Context) {
2930fn goto_first_diag(cx: &mut Context) {
2939 let (view, doc) = current!(cx.editor);
2931 let (view, doc) = current!(cx.editor);
2940 let selection = match doc.diagnostics().first() {
2932 let selection = match doc.diagnostics().first() {
@@ -3012,7 +3004,7 @@ fn goto_last_change(cx: &mut Context) {
3013fn goto_first_change_impl(cx: &mut Context, reverse: bool) {
3005fn goto_first_change_impl(cx: &mut Context, reverse: bool) {
3014 let editor = &mut cx.editor;
3006 let editor = &mut cx.editor;
3015− let (_, doc) = current!(editor);
3007+ let (view, doc) = current!(editor);
3016 if let Some(handle) = doc.diff_handle() {
3008 if let Some(handle) = doc.diff_handle() {
3017 let hunk = {
3009 let hunk = {
3018 let hunks = handle.hunks();
3010 let hunks = handle.hunks();
@@ -3024,8 +3016,8 @@ fn goto_first_change_impl(cx: &mut Context, reverse: bool) {
3024 hunks.nth_hunk(idx)
3016 hunks.nth_hunk(idx)
3026 if hunk != Hunk::NONE {
3018 if hunk != Hunk::NONE {
3027− let pos = doc.text().line_to_char(hunk.after.start as usize);
3019+ let range = hunk_range(hunk, doc.text().slice(..));
3028− goto_pos(editor, pos)
3020+ doc.set_selection(view.id, Selection::single(range.anchor, range.head));
@@ -3069,14 +3061,7 @@ fn goto_next_change_impl(cx: &mut Context, direction: Direction) {
3069 return range;
3061 return range;
3071 let hunk = hunks.nth_hunk(hunk_idx);
3063 let hunk = hunks.nth_hunk(hunk_idx);
3072−
3064+ let new_range = hunk_range(hunk, doc_text);
3073− let hunk_start = doc_text.line_to_char(hunk.after.start as usize);
3074− let hunk_end = if hunk.after.is_empty() {
3077− doc_text.line_to_char(hunk.after.end as usize)
3079− let new_range = Range::new(hunk_start, hunk_end);
3080 if editor.mode == Mode::Select {
3065 if editor.mode == Mode::Select {
3081 let head = if new_range.head < range.anchor {
3066 let head = if new_range.head < range.anchor {
3082 new_range.anchor
3067 new_range.anchor
@@ -3096,6 +3081,20 @@ fn goto_next_change_impl(cx: &mut Context, direction: Direction) {
3096 cx.editor.last_motion = Some(Motion(Box::new(motion)));
3081 cx.editor.last_motion = Some(Motion(Box::new(motion)));
3084+/// Returns the [Range] for a [Hunk] in the given text.
3085+/// Additions and modifications cover the added and modified ranges.
3086+/// Deletions are represented as the point at the start of the deletion hunk.
3087+fn hunk_range(hunk: Hunk, text: RopeSlice) -> Range {
3088+ let anchor = text.line_to_char(hunk.after.start as usize);
3089+ let head = if hunk.after.is_empty() {
3092+ text.line_to_char(hunk.after.end as usize)
3095+ Range::new(anchor, head)
3099pub mod insert {
3098pub mod insert {
3100 use super::*;
3099 use super::*;
3101 pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;
3100 pub type Hook = fn(&Rope, &Selection, char) -> Option<Transaction>;