aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/editor.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-09-01 07:14:38 +0000
committerBlaž Hrastnik2022-09-01 07:14:38 +0000
commit5c2b77b41fadd0e65e02455d36d8509f622bc520 (patch)
tree57bb35e6cb6e9c0cc55237cb02d3a409203f8abc /helix-view/src/editor.rs
parent10d9355b340f65ba534c66772e9d930188ed0a1b (diff)
Make mode editor-wide rather than per-document
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 0bf7ebd0..ed1813b3 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -595,6 +595,8 @@ pub struct Breakpoint {
}
pub struct Editor {
+ /// Current editing mode.
+ pub mode: Mode,
pub tree: Tree,
pub next_document_id: DocumentId,
pub documents: BTreeMap<DocumentId, Document>,
@@ -677,6 +679,7 @@ impl Editor {
area.height -= 1;
Self {
+ mode: Mode::Normal,
tree: Tree::new(area),
next_document_id: DocumentId::default(),
documents: BTreeMap::new(),
@@ -708,6 +711,11 @@ impl Editor {
}
}
+ /// Current editing mode for the [`Editor`].
+ pub fn mode(&self) -> Mode {
+ self.mode
+ }
+
pub fn config(&self) -> DynGuard<Config> {
self.config.load()
}
@@ -1103,8 +1111,7 @@ impl Editor {
// if leaving the view: mode should reset
if prev_id != view_id {
- let doc_id = self.tree.get(prev_id).doc;
- self.documents.get_mut(&doc_id).unwrap().mode = Mode::Normal;
+ self.mode = Mode::Normal;
}
}
@@ -1115,8 +1122,7 @@ impl Editor {
// if leaving the view: mode should reset
if prev_id != id {
- let doc_id = self.tree.get(prev_id).doc;
- self.documents.get_mut(&doc_id).unwrap().mode = Mode::Normal;
+ self.mode = Mode::Normal;
}
}
@@ -1187,7 +1193,7 @@ impl Editor {
let inner = view.inner_area();
pos.col += inner.x as usize;
pos.row += inner.y as usize;
- let cursorkind = config.cursor_shape.from_mode(doc.mode());
+ let cursorkind = config.cursor_shape.from_mode(self.mode);
(Some(pos), cursorkind)
} else {
(None, CursorKind::default())