diff options
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r-- | helix-view/src/editor.rs | 16 |
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()) |