diff --git a/zed/src/editor.rs b/zed/src/editor.rs index b8c9601fe26a371e63f4d2247fd9a02382d3ca86..71a9174f2ee1fa5b43dd1bfeeadd9aca887426ee 100644 --- a/zed/src/editor.rs +++ b/zed/src/editor.rs @@ -27,6 +27,7 @@ use serde::{Deserialize, Serialize}; use smallvec::SmallVec; use smol::Timer; use std::{ + cell::RefCell, cmp::{self, Ordering}, collections::BTreeMap, fmt::Write, @@ -34,6 +35,7 @@ use std::{ mem, ops::{Range, RangeInclusive}, path::Path, + rc::Rc, sync::Arc, time::Duration, }; @@ -288,7 +290,7 @@ pub struct Editor { scroll_position: Vector2F, scroll_top_anchor: Anchor, autoscroll_requested: bool, - build_style: Option EditorStyle>>, + build_style: Option EditorStyle>>>, settings: watch::Receiver, focused: bool, cursors_visible: bool, @@ -389,7 +391,7 @@ impl Editor { mut self, f: impl 'static + FnMut(&mut MutableAppContext) -> EditorStyle, ) -> Self { - self.build_style = Some(Box::new(f)); + self.build_style = Some(Rc::new(RefCell::new(f))); self } @@ -2582,8 +2584,8 @@ impl View for Editor { fn render(&mut self, cx: &mut RenderContext) -> ElementBox { let style = self .build_style - .as_mut() - .map_or(Default::default(), |build| build(cx)); + .as_ref() + .map_or(Default::default(), |build| (build.borrow_mut())(cx)); EditorElement::new(self.handle.clone(), style).boxed() } @@ -2665,6 +2667,7 @@ impl workspace::ItemView for Editor { let mut clone = Editor::for_buffer(self.buffer.clone(), self.settings.clone(), cx); clone.scroll_position = self.scroll_position; clone.scroll_top_anchor = self.scroll_top_anchor.clone(); + clone.build_style = self.build_style.clone(); Some(clone) }