Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs57
1 files changed, 36 insertions, 21 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 7e0bee92..2c5d2783 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1032,6 +1032,7 @@ fn goto_window(cx: &mut Context, align: Align) {
let count = cx.count() - 1;
let config = cx.editor.config();
let (view, doc) = current!(cx.editor);
+ let view_offset = doc.view_offset(view.id);
let height = view.inner_height();
@@ -1044,15 +1045,15 @@ fn goto_window(cx: &mut Context, align: Align) {
let last_visual_line = view.last_visual_line(doc);
let visual_line = match align {
- Align::Top => view.offset.vertical_offset + scrolloff + count,
- Align::Center => view.offset.vertical_offset + (last_visual_line / 2),
+ Align::Top => view_offset.vertical_offset + scrolloff + count,
+ Align::Center => view_offset.vertical_offset + (last_visual_line / 2),
Align::Bottom => {
- view.offset.vertical_offset + last_visual_line.saturating_sub(scrolloff + count)
+ view_offset.vertical_offset + last_visual_line.saturating_sub(scrolloff + count)
}
};
let visual_line = visual_line
- .max(view.offset.vertical_offset + scrolloff)
- .min(view.offset.vertical_offset + last_visual_line.saturating_sub(scrolloff));
+ .max(view_offset.vertical_offset + scrolloff)
+ .min(view_offset.vertical_offset + last_visual_line.saturating_sub(scrolloff));
let pos = view
.pos_at_visual_coords(doc, visual_line as u16, 0, false)
@@ -1665,6 +1666,7 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction, sync_cursor
use Direction::*;
let config = cx.editor.config();
let (view, doc) = current!(cx.editor);
+ let mut view_offset = doc.view_offset(view.id);
let range = doc.selection(view.id).primary();
let text = doc.text().slice(..);
@@ -1681,15 +1683,19 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction, sync_cursor
let doc_text = doc.text().slice(..);
let viewport = view.inner_area(doc);
let text_fmt = doc.text_format(viewport.width, None);
- let mut annotations = view.text_annotations(&*doc, None);
- (view.offset.anchor, view.offset.vertical_offset) = char_idx_at_visual_offset(
+ (view_offset.anchor, view_offset.vertical_offset) = char_idx_at_visual_offset(
doc_text,
- view.offset.anchor,
- view.offset.vertical_offset as isize + offset,
+ view_offset.anchor,
+ view_offset.vertical_offset as isize + offset,
0,
&text_fmt,
- &annotations,
+ // &annotations,
+ &view.text_annotations(&*doc, None),
);
+ doc.set_view_offset(view.id, view_offset);
+
+ let doc_text = doc.text().slice(..);
+ let mut annotations = view.text_annotations(&*doc, None);
if sync_cursor {
let movement = match cx.editor.mode {
@@ -1716,14 +1722,16 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction, sync_cursor
return;
}
+ let view_offset = doc.view_offset(view.id);
+
let mut head;
match direction {
Forward => {
let off;
(head, off) = char_idx_at_visual_offset(
doc_text,
- view.offset.anchor,
- (view.offset.vertical_offset + scrolloff) as isize,
+ view_offset.anchor,
+ (view_offset.vertical_offset + scrolloff) as isize,
0,
&text_fmt,
&annotations,
@@ -1736,8 +1744,8 @@ pub fn scroll(cx: &mut Context, offset: usize, direction: Direction, sync_cursor
Backward => {
head = char_idx_at_visual_offset(
doc_text,
- view.offset.anchor,
- (view.offset.vertical_offset + height - scrolloff - 1) as isize,
+ view_offset.anchor,
+ (view_offset.vertical_offset + height - scrolloff - 1) as isize,
0,
&text_fmt,
&annotations,
@@ -5124,7 +5132,7 @@ fn split(editor: &mut Editor, action: Action) {
let (view, doc) = current!(editor);
let id = doc.id();
let selection = doc.selection(view.id).clone();
- let offset = view.offset;
+ let offset = doc.view_offset(view.id);
editor.switch(id, action);
@@ -5133,7 +5141,7 @@ fn split(editor: &mut Editor, action: Action) {
doc.set_selection(view.id, selection);
// match the view scroll offset (switch doesn't handle this fully
// since the selection is only matched after the split)
- view.offset = offset;
+ doc.set_view_offset(view.id, offset);
}
fn hsplit(cx: &mut Context) {
@@ -5228,14 +5236,21 @@ fn align_view_middle(cx: &mut Context) {
return;
}
let doc_text = doc.text().slice(..);
- let annotations = view.text_annotations(doc, None);
let pos = doc.selection(view.id).primary().cursor(doc_text);
- let pos =
- visual_offset_from_block(doc_text, view.offset.anchor, pos, &text_fmt, &annotations).0;
+ let pos = visual_offset_from_block(
+ doc_text,
+ doc.view_offset(view.id).anchor,
+ pos,
+ &text_fmt,
+ &view.text_annotations(doc, None),
+ )
+ .0;
- view.offset.horizontal_offset = pos
+ let mut offset = doc.view_offset(view.id);
+ offset.horizontal_offset = pos
.col
.saturating_sub((view.inner_area(doc).width as usize) / 2);
+ doc.set_view_offset(view.id, offset);
}
fn scroll_up(cx: &mut Context) {
@@ -6117,7 +6132,7 @@ fn jump_to_word(cx: &mut Context, behaviour: Movement) {
// This is not necessarily exact if there is virtual text like soft wrap.
// It's ok though because the extra jump labels will not be rendered.
- let start = text.line_to_char(text.char_to_line(view.offset.anchor));
+ let start = text.line_to_char(text.char_to_line(doc.view_offset(view.id).anchor));
let end = text.line_to_char(view.estimate_last_doc_line(doc) + 1);
let primary_selection = doc.selection(view.id).primary();