Fix deprecation warning text being covered by right dock (#30456)

Closes [#30378](https://github.com/zed-industries/zed/issues/30378)

Release Notes:

- Fixed deprecation warning text being covered by right dock

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
Sergei Kartsev 2025-05-11 23:54:21 +02:00 committed by GitHub
parent ae31aa2759
commit cee9f4b013
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 86 additions and 60 deletions

1
Cargo.lock generated
View file

@ -18593,6 +18593,7 @@ dependencies = [
"languages", "languages",
"libc", "libc",
"log", "log",
"markdown",
"markdown_preview", "markdown_preview",
"menu", "menu",
"migrator", "migrator",

View file

@ -78,6 +78,7 @@ languages = { workspace = true, features = ["load-grammars"] }
libc.workspace = true libc.workspace = true
log.workspace = true log.workspace = true
markdown_preview.workspace = true markdown_preview.workspace = true
markdown.workspace = true
menu.workspace = true menu.workspace = true
migrator.workspace = true migrator.workspace = true
mimalloc = { version = "0.1", optional = true } mimalloc = { version = "0.1", optional = true }

View file

@ -2,12 +2,14 @@ use anyhow::{Context as _, Result};
use editor::Editor; use editor::Editor;
use fs::Fs; use fs::Fs;
use migrator::{migrate_keymap, migrate_settings}; use migrator::{migrate_keymap, migrate_settings};
use settings::{KeymapFile, SettingsStore}; use settings::{KeymapFile, Settings, SettingsStore};
use util::ResultExt; use util::ResultExt;
use std::sync::Arc; use std::sync::Arc;
use gpui::{Entity, EventEmitter, Global, Task}; use gpui::{Entity, EventEmitter, Global, Task, TextStyle, TextStyleRefinement};
use markdown::{Markdown, MarkdownElement, MarkdownStyle};
use theme::ThemeSettings;
use ui::prelude::*; use ui::prelude::*;
use workspace::item::ItemHandle; use workspace::item::ItemHandle;
use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace}; use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace};
@ -21,6 +23,7 @@ pub enum MigrationType {
pub struct MigrationBanner { pub struct MigrationBanner {
migration_type: Option<MigrationType>, migration_type: Option<MigrationType>,
should_migrate_task: Option<Task<()>>, should_migrate_task: Option<Task<()>>,
markdown: Option<Entity<Markdown>>,
} }
pub enum MigrationEvent { pub enum MigrationEvent {
@ -63,22 +66,7 @@ impl MigrationBanner {
Self { Self {
migration_type: None, migration_type: None,
should_migrate_task: None, should_migrate_task: None,
} markdown: None,
}
fn backup_file_name(&self) -> String {
match self.migration_type {
Some(MigrationType::Keymap) => paths::keymap_backup_file()
.file_name()
.unwrap_or_default()
.to_string_lossy()
.into_owned(),
Some(MigrationType::Settings) => paths::settings_backup_file()
.file_name()
.unwrap_or_default()
.to_string_lossy()
.into_owned(),
None => String::new(),
} }
} }
@ -100,6 +88,48 @@ impl MigrationBanner {
} }
} }
} }
fn show(&mut self, cx: &mut Context<Self>) {
let (file_type, backup_file_name) = match self.migration_type {
Some(MigrationType::Keymap) => (
"keymap",
paths::keymap_backup_file()
.file_name()
.unwrap_or_default()
.to_string_lossy()
.into_owned(),
),
Some(MigrationType::Settings) => (
"settings",
paths::settings_backup_file()
.file_name()
.unwrap_or_default()
.to_string_lossy()
.into_owned(),
),
None => return,
};
let migration_text = format!(
"Your {} file uses deprecated settings which can be \
automatically updated. A backup will be saved to `{}`",
file_type, backup_file_name
);
self.markdown = Some(cx.new(|cx| Markdown::new(migration_text.into(), None, None, cx)));
cx.emit(ToolbarItemEvent::ChangeLocation(
ToolbarItemLocation::Secondary,
));
cx.notify();
}
fn reset(&mut self, cx: &mut Context<Self>) {
self.should_migrate_task.take();
self.migration_type.take();
self.markdown.take();
cx.notify();
}
} }
impl EventEmitter<ToolbarItemEvent> for MigrationBanner {} impl EventEmitter<ToolbarItemEvent> for MigrationBanner {}
@ -111,8 +141,8 @@ impl ToolbarItemView for MigrationBanner {
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> ToolbarItemLocation { ) -> ToolbarItemLocation {
cx.notify(); self.reset(cx);
self.should_migrate_task.take();
let Some(target) = active_pane_item let Some(target) = active_pane_item
.and_then(|item| item.act_as::<Editor>(cx)) .and_then(|item| item.act_as::<Editor>(cx))
.and_then(|editor| editor.update(cx, |editor, cx| editor.target_file_abs_path(cx))) .and_then(|editor| editor.update(cx, |editor, cx| editor.target_file_abs_path(cx)))
@ -126,11 +156,8 @@ impl ToolbarItemView for MigrationBanner {
let should_migrate = should_migrate_keymap(fs); let should_migrate = should_migrate_keymap(fs);
self.should_migrate_task = Some(cx.spawn_in(window, async move |this, cx| { self.should_migrate_task = Some(cx.spawn_in(window, async move |this, cx| {
if let Ok(true) = should_migrate.await { if let Ok(true) = should_migrate.await {
this.update(cx, |_, cx| { this.update(cx, |this, cx| {
cx.emit(ToolbarItemEvent::ChangeLocation( this.show(cx);
ToolbarItemLocation::Secondary,
));
cx.notify();
}) })
.log_err(); .log_err();
} }
@ -141,11 +168,8 @@ impl ToolbarItemView for MigrationBanner {
let should_migrate = should_migrate_settings(fs); let should_migrate = should_migrate_settings(fs);
self.should_migrate_task = Some(cx.spawn_in(window, async move |this, cx| { self.should_migrate_task = Some(cx.spawn_in(window, async move |this, cx| {
if let Ok(true) = should_migrate.await { if let Ok(true) = should_migrate.await {
this.update(cx, |_, cx| { this.update(cx, |this, cx| {
cx.emit(ToolbarItemEvent::ChangeLocation( this.show(cx);
ToolbarItemLocation::Secondary,
));
cx.notify();
}) })
.log_err(); .log_err();
} }
@ -159,54 +183,54 @@ impl ToolbarItemView for MigrationBanner {
impl Render for MigrationBanner { impl Render for MigrationBanner {
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let migration_type = self.migration_type; let migration_type = self.migration_type;
let file_type = match migration_type { let settings = ThemeSettings::get_global(cx);
Some(MigrationType::Keymap) => "keymap", let ui_font_family = settings.ui_font.family.clone();
Some(MigrationType::Settings) => "settings", let line_height = settings.ui_font_size(cx) * 1.3;
None => "",
};
let backup_file_name = self.backup_file_name();
h_flex() h_flex()
.py_1() .py_1()
.pl_2() .pl_2()
.pr_1() .pr_1()
.flex_wrap()
.justify_between() .justify_between()
.bg(cx.theme().status().info_background.opacity(0.6)) .bg(cx.theme().status().info_background.opacity(0.6))
.border_1() .border_1()
.border_color(cx.theme().colors().border_variant) .border_color(cx.theme().colors().border_variant)
.rounded_sm() .rounded_sm()
.overflow_hidden()
.child( .child(
h_flex() h_flex()
.gap_2() .gap_2()
.overflow_hidden()
.child( .child(
Icon::new(IconName::Warning) Icon::new(IconName::Warning)
.size(IconSize::XSmall) .size(IconSize::XSmall)
.color(Color::Warning), .color(Color::Warning),
) )
.child( .child(
h_flex() div()
.gap_0p5() .overflow_hidden()
.child( .text_size(TextSize::Default.rems(cx))
Label::new(format!( .max_h(2 * line_height)
"Your {} file uses deprecated settings which can be \ .when_some(self.markdown.as_ref(), |this, markdown| {
automatically updated. A backup will be saved to", this.child(
file_type MarkdownElement::new(
)) markdown.clone(),
.color(Color::Default), MarkdownStyle {
) base_text_style: TextStyle {
.child( color: cx.theme().colors().text,
div() font_family: ui_font_family,
.px_1() ..Default::default()
.bg(cx.theme().colors().background) },
.rounded_xs() inline_code: TextStyleRefinement {
.child( background_color: Some(
Label::new(backup_file_name) cx.theme().colors().background,
.buffer_font(cx) ),
.size(LabelSize::Small), ..Default::default()
), },
), ..Default::default()
},
)
.into_any_element(),
)
}),
), ),
) )
.child( .child(