aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Tham2021-10-29 01:07:07 +0000
committerGitHub2021-10-29 01:07:07 +0000
commit21d535565bfcc5ff4e2eae34329b051944a8d1f5 (patch)
treea052f8ab7a6c609deef2ae6dc3429f634826873b
parentbefecc8a9a087436a9dbc6942e328646c3391874 (diff)
Support extend for multiple goto (#909)
gg, ge, [n]gg
-rw-r--r--helix-term/src/commands.rs29
1 files changed, 25 insertions, 4 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 08750aeb..9eda2c23 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -622,14 +622,25 @@ fn goto_file_start(cx: &mut Context) {
} else {
push_jump(cx.editor);
let (view, doc) = current!(cx.editor);
- doc.set_selection(view.id, Selection::point(0));
+ let text = doc.text().slice(..);
+ let selection = doc
+ .selection(view.id)
+ .clone()
+ .transform(|range| range.put_cursor(text, 0, doc.mode == Mode::Select));
+ doc.set_selection(view.id, selection);
}
}
fn goto_file_end(cx: &mut Context) {
push_jump(cx.editor);
let (view, doc) = current!(cx.editor);
- doc.set_selection(view.id, Selection::point(doc.text().len_chars()));
+ let text = doc.text().slice(..);
+ let pos = doc.text().len_chars();
+ let selection = doc
+ .selection(view.id)
+ .clone()
+ .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
+ doc.set_selection(view.id, selection);
}
fn extend_word_impl<F>(cx: &mut Context, extend_fn: F)
@@ -2905,8 +2916,13 @@ fn goto_line(cx: &mut Context) {
doc.text().len_lines() - 1
};
let line_idx = std::cmp::min(count.get() - 1, max_line);
+ let text = doc.text().slice(..);
let pos = doc.text().line_to_char(line_idx);
- doc.set_selection(view.id, Selection::point(pos));
+ let selection = doc
+ .selection(view.id)
+ .clone()
+ .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
+ doc.set_selection(view.id, selection);
}
}
@@ -2920,8 +2936,13 @@ fn goto_last_line(cx: &mut Context) {
} else {
doc.text().len_lines() - 1
};
+ let text = doc.text().slice(..);
let pos = doc.text().line_to_char(line_idx);
- doc.set_selection(view.id, Selection::point(pos));
+ let selection = doc
+ .selection(view.id)
+ .clone()
+ .transform(|range| range.put_cursor(text, pos, doc.mode == Mode::Select));
+ doc.set_selection(view.id, selection);
}
fn goto_last_accessed_file(cx: &mut Context) {