From 5c2b77b41fadd0e65e02455d36d8509f622bc520 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Thu, 1 Sep 2022 16:14:38 +0900 Subject: Make mode editor-wide rather than per-document --- helix-view/src/editor.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'helix-view/src/editor.rs') 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, @@ -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 { 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()) -- cgit v1.2.3-70-g09d2