Replace zed::watch with postage::watch for settings
Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
co-authored by
Max Brunsfeld
parent
ab10e27424
commit
4eac765f1a
@@ -2,7 +2,7 @@ use super::{
|
||||
buffer, movement, Anchor, Bias, Buffer, BufferElement, DisplayMap, DisplayPoint, Point,
|
||||
Selection, SelectionSetId, ToOffset, ToPoint,
|
||||
};
|
||||
use crate::{settings::Settings, watch, workspace, worktree::FileHandle};
|
||||
use crate::{settings::Settings, workspace, worktree::FileHandle};
|
||||
use anyhow::Result;
|
||||
use futures_core::future::LocalBoxFuture;
|
||||
use gpui::{
|
||||
@@ -12,6 +12,7 @@ use gpui::{
|
||||
};
|
||||
use gpui::{geometry::vector::Vector2F, TextLayoutCache};
|
||||
use parking_lot::Mutex;
|
||||
use postage::watch;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use smallvec::SmallVec;
|
||||
use smol::Timer;
|
||||
@@ -288,19 +289,13 @@ impl BufferView {
|
||||
settings: watch::Receiver<Settings>,
|
||||
ctx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
settings.notify_view_on_change(ctx);
|
||||
|
||||
if let Some(file) = file.as_ref() {
|
||||
file.observe_from_view(ctx, |_, _, ctx| ctx.emit(Event::FileHandleChanged));
|
||||
}
|
||||
|
||||
ctx.observe_model(&buffer, Self::on_buffer_changed);
|
||||
ctx.subscribe_to_model(&buffer, Self::on_buffer_event);
|
||||
let display_map = DisplayMap::new(
|
||||
buffer.clone(),
|
||||
smol::block_on(settings.read()).tab_size,
|
||||
ctx.as_ref(),
|
||||
);
|
||||
let display_map = DisplayMap::new(buffer.clone(), settings.borrow().tab_size, ctx.as_ref());
|
||||
|
||||
let (selection_set_id, _) = buffer.update(ctx, |buffer, ctx| {
|
||||
buffer.add_selection_set(
|
||||
@@ -1924,31 +1919,31 @@ impl BufferView {
|
||||
}
|
||||
|
||||
pub fn font_size(&self) -> f32 {
|
||||
smol::block_on(self.settings.read()).buffer_font_size
|
||||
self.settings.borrow().buffer_font_size
|
||||
}
|
||||
|
||||
pub fn font_ascent(&self, font_cache: &FontCache) -> f32 {
|
||||
let settings = smol::block_on(self.settings.read());
|
||||
let settings = self.settings.borrow();
|
||||
let font_id = font_cache.default_font(settings.buffer_font_family);
|
||||
let ascent = font_cache.metric(font_id, |m| m.ascent);
|
||||
font_cache.scale_metric(ascent, font_id, settings.buffer_font_size)
|
||||
}
|
||||
|
||||
pub fn font_descent(&self, font_cache: &FontCache) -> f32 {
|
||||
let settings = smol::block_on(self.settings.read());
|
||||
let settings = self.settings.borrow();
|
||||
let font_id = font_cache.default_font(settings.buffer_font_family);
|
||||
let ascent = font_cache.metric(font_id, |m| m.descent);
|
||||
font_cache.scale_metric(ascent, font_id, settings.buffer_font_size)
|
||||
}
|
||||
|
||||
pub fn line_height(&self, font_cache: &FontCache) -> f32 {
|
||||
let settings = smol::block_on(self.settings.read());
|
||||
let settings = self.settings.borrow();
|
||||
let font_id = font_cache.default_font(settings.buffer_font_family);
|
||||
font_cache.line_height(font_id, settings.buffer_font_size)
|
||||
}
|
||||
|
||||
pub fn em_width(&self, font_cache: &FontCache) -> f32 {
|
||||
let settings = smol::block_on(self.settings.read());
|
||||
let settings = self.settings.borrow();
|
||||
let font_id = font_cache.default_font(settings.buffer_font_family);
|
||||
font_cache.em_width(font_id, settings.buffer_font_size)
|
||||
}
|
||||
@@ -1960,7 +1955,7 @@ impl BufferView {
|
||||
layout_cache: &TextLayoutCache,
|
||||
app: &AppContext,
|
||||
) -> Result<f32> {
|
||||
let settings = smol::block_on(self.settings.read());
|
||||
let settings = self.settings.borrow();
|
||||
let font_size = settings.buffer_font_size;
|
||||
let font_id =
|
||||
font_cache.select_font(settings.buffer_font_family, &FontProperties::new())?;
|
||||
@@ -1985,7 +1980,7 @@ impl BufferView {
|
||||
layout_cache: &TextLayoutCache,
|
||||
ctx: &AppContext,
|
||||
) -> Result<Vec<Arc<text_layout::Line>>> {
|
||||
let settings = smol::block_on(self.settings.read());
|
||||
let settings = self.settings.borrow();
|
||||
let font_size = settings.buffer_font_size;
|
||||
let font_id =
|
||||
font_cache.select_font(settings.buffer_font_family, &FontProperties::new())?;
|
||||
@@ -2029,7 +2024,7 @@ impl BufferView {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let settings = smol::block_on(self.settings.read());
|
||||
let settings = self.settings.borrow();
|
||||
let font_id =
|
||||
font_cache.select_font(settings.buffer_font_family, &FontProperties::new())?;
|
||||
let font_size = settings.buffer_font_size;
|
||||
@@ -2067,7 +2062,7 @@ impl BufferView {
|
||||
layout_cache: &TextLayoutCache,
|
||||
app: &AppContext,
|
||||
) -> Result<Arc<text_layout::Line>> {
|
||||
let settings = smol::block_on(self.settings.read());
|
||||
let settings = self.settings.borrow();
|
||||
let font_id =
|
||||
font_cache.select_font(settings.buffer_font_family, &FontProperties::new())?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user