aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src/editor.rs
diff options
context:
space:
mode:
authorBenoît CORTIER2021-06-17 22:09:10 +0000
committerBlaž Hrastnik2021-06-18 00:38:10 +0000
commit8664d70e731c73fa34dda293b4f6b6dec80a3273 (patch)
tree3535c4376533fb19323afc60a8d6d223326ace77 /helix-view/src/editor.rs
parentf65db9397a2d832f7ef873ea416f13f8fb07cb74 (diff)
Replace `Editor::current` by a macro
This is necessary to workaround ownership issues across function calls. The issue notably arised when implementing the registers into `Editor` and I was getting annoyed again when implementing copy/pasting into system clipboard. The problem is addressed by using macro calls instead of function calls. There is no notable side effect.
Diffstat (limited to 'helix-view/src/editor.rs')
-rw-r--r--helix-view/src/editor.rs29
1 files changed, 4 insertions, 25 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 24f43c0e..a1c93f75 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -101,19 +101,19 @@ impl Editor {
match action {
Action::Replace => {
- let view = self.view();
+ let view = view!(self);
let jump = (
view.doc,
self.documents[view.doc].selection(view.id).clone(),
);
- let view = self.view_mut();
+ let view = view_mut!(self);
view.jumps.push(jump);
view.last_accessed_doc = Some(view.doc);
view.doc = id;
view.first_line = 0;
- let (view, doc) = self.current();
+ let (view, doc) = current!(self);
// initialize selection for view
let selection = doc
@@ -238,27 +238,6 @@ impl Editor {
self.tree.is_empty()
}
- pub fn current(&mut self) -> (&mut View, &mut Document) {
- let view = self.tree.get_mut(self.tree.focus);
- let doc = &mut self.documents[view.doc];
- (view, doc)
- }
-
- pub fn current_with_registers(&mut self) -> (&mut View, &mut Document, &mut Registers) {
- let view = self.tree.get_mut(self.tree.focus);
- let doc = &mut self.documents[view.doc];
- let registers = &mut self.registers;
- (view, doc, registers)
- }
-
- pub fn view(&self) -> &View {
- self.tree.get(self.tree.focus)
- }
-
- pub fn view_mut(&mut self) -> &mut View {
- self.tree.get_mut(self.tree.focus)
- }
-
pub fn ensure_cursor_in_view(&mut self, id: ViewId) {
let view = self.tree.get_mut(id);
let doc = &self.documents[view.doc];
@@ -280,7 +259,7 @@ impl Editor {
pub fn cursor(&self) -> (Option<Position>, CursorKind) {
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
- let view = self.view();
+ let view = view!(self);
let doc = &self.documents[view.doc];
let cursor = doc.selection(view.id).cursor();
if let Some(mut pos) = view.screen_coords_at_pos(doc, doc.text().slice(..), cursor) {