aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/document.rs9
-rw-r--r--helix-view/src/editor.rs16
-rw-r--r--helix-view/src/gutter.rs2
3 files changed, 12 insertions, 15 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index b2a66415..3c406f8b 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -90,8 +90,6 @@ pub struct Document {
path: Option<PathBuf>,
encoding: &'static encoding::Encoding,
- /// Current editing mode.
- pub mode: Mode,
pub restore_cursor: bool,
/// Current indent style.
@@ -133,7 +131,6 @@ impl fmt::Debug for Document {
.field("selections", &self.selections)
.field("path", &self.path)
.field("encoding", &self.encoding)
- .field("mode", &self.mode)
.field("restore_cursor", &self.restore_cursor)
.field("syntax", &self.syntax)
.field("language", &self.language)
@@ -349,7 +346,6 @@ impl Document {
selections: HashMap::default(),
indent_style: DEFAULT_INDENT,
line_ending: DEFAULT_LINE_ENDING,
- mode: Mode::Normal,
restore_cursor: false,
syntax: None,
language: None,
@@ -925,11 +921,6 @@ impl Document {
self.last_saved_revision = current_revision;
}
- /// Current editing mode for the [`Document`].
- pub fn mode(&self) -> Mode {
- self.mode
- }
-
/// Corresponding language scope name. Usually `source.<lang>`.
pub fn language_scope(&self) -> Option<&str> {
self.language
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())
diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs
index 8f7c3062..ab0e2986 100644
--- a/helix-view/src/gutter.rs
+++ b/helix-view/src/gutter.rs
@@ -72,7 +72,7 @@ pub fn line_numbers<'doc>(
.char_to_line(doc.selection(view.id).primary().cursor(text));
let line_number = editor.config().line_number;
- let mode = doc.mode;
+ let mode = editor.mode;
Box::new(move |line: usize, selected: bool, out: &mut String| {
if line == last_line && !draw_last {