diff options
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/document.rs | 6 | ||||
-rw-r--r-- | helix-view/src/view.rs | 11 |
2 files changed, 15 insertions, 2 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 569e72ee..3f3f620f 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -140,10 +140,12 @@ impl Document { // TODO: this ties lsp support to tree-sitter enabled languages for now. Language // config should use Option<HighlightConfig> to let us have non-tree-sitter configs. - let highlight_config = language_config.highlight_config(scopes).unwrap().unwrap(); + let highlight_config = language_config + .highlight_config(scopes) + .expect("No highlight_config found!"); // TODO: config.configure(scopes) is now delayed, is that ok? - let syntax = Syntax::new(&self.state.doc, highlight_config.clone()); + let syntax = Syntax::new(&self.state.doc, highlight_config); self.syntax = Some(syntax); } else { diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs index e02436b3..f3d92bfd 100644 --- a/helix-view/src/view.rs +++ b/helix-view/src/view.rs @@ -35,6 +35,17 @@ impl View { Ok(view) } + pub fn check_cursor_in_view(&self) -> bool { + let cursor = self.doc.selection().cursor(); + let line = self.doc.text().char_to_line(cursor); + let document_end = self.first_line + self.area.height.saturating_sub(1) as usize; + + if (line > document_end.saturating_sub(PADDING)) || (line < self.first_line + PADDING) { + return false; + } + true + } + pub fn ensure_cursor_in_view(&mut self) { let cursor = self.doc.state.selection().cursor(); let line = self.doc.text().char_to_line(cursor); |