summaryrefslogtreecommitdiff
path: root/helix-view/src/editor.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-31 08:17:01 +0000
committerBlaž Hrastnik2021-03-31 08:17:01 +0000
commit6c4093c94634a94adbccb4783cddb90076881c02 (patch)
tree34d4691fe6daca0d14ce77b434830cdef72deb47 /helix-view/src/editor.rs
parent9eaef6e33376407931162780cd402297c44f26c4 (diff)
Weave through view_id references so that views into one file have independent selects.
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs27
1 files changed, 23 insertions, 4 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index f062b55d..f74bbb13 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -91,24 +91,40 @@ impl Editor {
};
use crate::tree::Layout;
+ use helix_core::Selection;
match action {
Action::Replace => {
let view = self.view();
- let jump = (view.doc, self.documents[view.doc].selection().clone());
+ let jump = (
+ view.doc,
+ self.documents[view.doc].selection(view.id).clone(),
+ );
let view = self.view_mut();
view.jumps.push(jump);
view.doc = id;
view.first_line = 0;
+ let view_id = view.id;
+
+ // initialize selection for view
+ let doc = &mut self.documents[id];
+ doc.selections.insert(view_id, Selection::point(0));
+
return Ok(id);
}
Action::HorizontalSplit => {
let view = View::new(id)?;
- self.tree.split(view, Layout::Horizontal);
+ let view_id = self.tree.split(view, Layout::Horizontal);
+ // initialize selection for view
+ let doc = &mut self.documents[id];
+ doc.selections.insert(view_id, Selection::point(0));
}
Action::VerticalSplit => {
let view = View::new(id)?;
- self.tree.split(view, Layout::Vertical);
+ let view_id = self.tree.split(view, Layout::Vertical);
+ // initialize selection for view
+ let doc = &mut self.documents[id];
+ doc.selections.insert(view_id, Selection::point(0));
}
}
@@ -134,6 +150,9 @@ impl Editor {
smol::block_on(language_server.text_document_did_close(doc.identifier())).unwrap();
}
+ // remove selection
+ self.documents[view.doc].selections.remove(&id);
+
// self.documents.remove(view.doc);
self.tree.remove(id);
self._refresh();
@@ -183,7 +202,7 @@ impl Editor {
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
let view = self.view();
let doc = &self.documents[view.doc];
- let cursor = doc.selection().cursor();
+ let cursor = doc.selection(view.id).cursor();
if let Some(mut pos) = view.screen_coords_at_pos(doc, doc.text().slice(..), cursor) {
pos.col += view.area.x as usize + OFFSET as usize;
pos.row += view.area.y as usize;