mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 11:01:54 +00:00
Merge pull request #2318 from zed-industries/fix-unknown-in-non-editor-buffers
changed language status bar item to only show on editors
This commit is contained in:
parent
1a277e97c1
commit
0241e51fb2
1 changed files with 23 additions and 19 deletions
|
@ -8,7 +8,7 @@ use std::sync::Arc;
|
|||
use workspace::{item::ItemHandle, StatusItemView};
|
||||
|
||||
pub struct ActiveBufferLanguage {
|
||||
active_language: Option<Arc<str>>,
|
||||
active_language: Option<Option<Arc<str>>>,
|
||||
_observe_active_editor: Option<Subscription>,
|
||||
}
|
||||
|
||||
|
@ -27,12 +27,12 @@ impl ActiveBufferLanguage {
|
|||
}
|
||||
|
||||
fn update_language(&mut self, editor: ViewHandle<Editor>, cx: &mut ViewContext<Self>) {
|
||||
self.active_language.take();
|
||||
self.active_language = Some(None);
|
||||
|
||||
let editor = editor.read(cx);
|
||||
if let Some((_, buffer, _)) = editor.active_excerpt(cx) {
|
||||
if let Some(language) = buffer.read(cx).language() {
|
||||
self.active_language = Some(language.name());
|
||||
self.active_language = Some(Some(language.name()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,9 @@ impl View for ActiveBufferLanguage {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
let active_language = if let Some(active_language) = self.active_language.as_ref() {
|
||||
active_language.to_string()
|
||||
if let Some(active_language) = self.active_language.as_ref() {
|
||||
let active_language_text = if let Some(active_language_text) = active_language {
|
||||
active_language_text.to_string()
|
||||
} else {
|
||||
"Unknown".to_string()
|
||||
};
|
||||
|
@ -59,7 +60,7 @@ impl View for ActiveBufferLanguage {
|
|||
MouseEventHandler::<Self>::new(0, cx, |state, cx| {
|
||||
let theme = &cx.global::<Settings>().theme.workspace.status_bar;
|
||||
let style = theme.active_language.style_for(state, false);
|
||||
Label::new(active_language, style.text.clone())
|
||||
Label::new(active_language_text, style.text.clone())
|
||||
.contained()
|
||||
.with_style(style.container)
|
||||
.boxed()
|
||||
|
@ -67,6 +68,9 @@ impl View for ActiveBufferLanguage {
|
|||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, |_, cx| cx.dispatch_action(crate::Toggle))
|
||||
.boxed()
|
||||
} else {
|
||||
Empty::new().boxed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue