diff options
author | Nathan Vegdahl | 2021-06-28 18:40:07 +0000 |
---|---|---|
committer | Nathan Vegdahl | 2021-07-01 21:22:28 +0000 |
commit | 0ae522f3df433bb778fa2ff98fd3d7047021c6ef (patch) | |
tree | 4b230419eb6e62d3de8937159aa34c60685368cc /helix-view/src | |
parent | 77a266e818bf9d2eded39816b6a77de140234e4f (diff) |
Clean up `Selection` to not use so many allocations.
Diffstat (limited to 'helix-view/src')
-rw-r--r-- | helix-view/src/document.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 0f1f3a8f..59a1c42c 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -13,8 +13,8 @@ use helix_core::{ history::History, line_ending::auto_detect_line_ending, syntax::{self, LanguageConfiguration}, - ChangeSet, Diagnostic, LineEnding, Rope, RopeBuilder, Selection, State, Syntax, Transaction, - DEFAULT_LINE_ENDING, + ChangeSet, Diagnostic, LineEnding, Rope, RopeBuilder, RopeSlice, Selection, State, Syntax, + Transaction, DEFAULT_LINE_ENDING, }; use helix_lsp::util::LspFormatting; @@ -1000,6 +1000,22 @@ impl Document { &self.selections[&view_id] } + #[inline] + pub fn selection_mut(&mut self, view_id: ViewId) -> &mut Selection { + self.selections + .get_mut(&view_id) + .expect("No selection set with the given ViewId") + } + + pub fn text_and_mut_selection(&mut self, view_id: ViewId) -> (RopeSlice, &mut Selection) { + ( + self.text.slice(..), + self.selections + .get_mut(&view_id) + .expect("No selection set with the given ViewId"), + ) + } + pub fn relative_path(&self) -> Option<PathBuf> { let cwdir = std::env::current_dir().expect("couldn't determine current directory"); |