summaryrefslogtreecommitdiff
path: root/helix-term
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-08-20 04:42:01 +0000
committerBlaž Hrastnik2021-08-20 04:42:01 +0000
commita76ec9a64e6c505ee0fdd5ee18e83390ac4a84ad (patch)
tree228d68d2ac0404805bdd648dbde4780b86c7c9f6 /helix-term
parent07fea61d03bef6004f5d2803e67c1175524fb74f (diff)
Make scrolling extend in extend mode
Diffstat (limited to 'helix-term')
-rw-r--r--helix-term/src/commands.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 7c3eeb4c..e7f482dd 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -882,12 +882,11 @@ fn switch_to_lowercase(cx: &mut Context) {
pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
use Direction::*;
let (view, doc) = current!(cx.editor);
- let cursor = coords_at_pos(
- doc.text().slice(..),
- doc.selection(view.id)
- .primary()
- .cursor(doc.text().slice(..)),
- );
+
+ let range = doc.selection(view.id).primary();
+ let text = doc.text().slice(..);
+
+ let cursor = coords_at_pos(text, range.cursor(text));
let doc_last_line = doc.text().len_lines().saturating_sub(1);
let last_line = view.last_line(doc);
@@ -917,11 +916,16 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
.max(view.offset.row + scrolloff)
.min(last_line.saturating_sub(scrolloff));
- let text = doc.text().slice(..);
- let pos = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
+ let head = pos_at_coords(text, Position::new(line, cursor.col), true); // this func will properly truncate to line end
+
+ let anchor = if doc.mode == Mode::Select {
+ range.anchor
+ } else {
+ head
+ };
// TODO: only manipulate main selection
- doc.set_selection(view.id, Selection::point(pos));
+ doc.set_selection(view.id, Selection::single(anchor, head));
}
fn page_up(cx: &mut Context) {