diff options
author | Blaž Hrastnik | 2022-08-23 05:07:50 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2022-08-23 05:07:50 +0000 |
commit | e4c9d4082a139aac3aea4506918171b96e81f5b9 (patch) | |
tree | ce6ce437ca62211806db3ba66f39d9adebfc83d2 /helix-view/src/editor.rs | |
parent | 7b8e4ac95a83513b315af29591ae957ae861605c (diff) |
fix: Reset document mode when losing focus
Fixes #3090
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r-- | helix-view/src/editor.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index d6c89693..520a425c 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1091,12 +1091,33 @@ impl Editor { }; } + pub fn focus(&mut self, view_id: ViewId) { + let prev_id = std::mem::replace(&mut self.tree.focus, view_id); + + // 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; + } + } + pub fn focus_next(&mut self) { + let prev_id = self.tree.focus; self.tree.focus_next(); + let id = self.tree.focus; + + // 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; + } } pub fn focus_direction(&mut self, direction: tree::Direction) { - self.tree.focus_direction(direction); + let current_view = self.tree.focus; + if let Some(id) = self.tree.find_split_in_direction(current_view, direction) { + self.focus(id) + } } pub fn swap_split_in_direction(&mut self, direction: tree::Direction) { |