Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from zed-industries:main #54

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5205,7 +5205,7 @@ impl Editor {
return;
};

if &accept_keystroke.modifiers == modifiers {
if &accept_keystroke.modifiers == modifiers && accept_keystroke.modifiers.modified() {
if matches!(
self.edit_prediction_preview,
EditPredictionPreview::Inactive
Expand Down
153 changes: 81 additions & 72 deletions crates/zed/src/zed/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use anyhow::{Context as _, Result};
use editor::Editor;
use fs::Fs;
use markdown_preview::markdown_elements::ParsedMarkdown;
use markdown_preview::markdown_renderer::render_parsed_markdown;
use migrator::{migrate_keymap, migrate_settings};
use settings::{KeymapFile, SettingsStore};
use util::markdown::MarkdownString;
use util::ResultExt;

use std::sync::Arc;

use gpui::{Entity, EventEmitter, Global, WeakEntity};
use gpui::{Entity, EventEmitter, Global};
use ui::prelude::*;
use workspace::item::ItemHandle;
use workspace::{ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace};
Expand All @@ -23,8 +20,6 @@ pub enum MigrationType {

pub struct MigratorBanner {
migration_type: Option<MigrationType>,
message: ParsedMarkdown,
workspace: WeakEntity<Workspace>,
}

pub enum MigratorEvent {
Expand Down Expand Up @@ -54,7 +49,7 @@ struct GlobalMigratorNotification(Entity<MigratorNotification>);
impl Global for GlobalMigratorNotification {}

impl MigratorBanner {
pub fn new(workspace: &Workspace, cx: &mut Context<'_, Self>) -> Self {
pub fn new(_: &Workspace, cx: &mut Context<'_, Self>) -> Self {
if let Some(notifier) = MigratorNotification::try_global(cx) {
cx.subscribe(
&notifier,
Expand All @@ -66,10 +61,25 @@ impl MigratorBanner {
}
Self {
migration_type: None,
message: ParsedMarkdown { children: vec![] },
workspace: workspace.weak_handle(),
}
}

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(),
}
}

fn handle_notification(&mut self, event: &MigratorEvent, cx: &mut Context<'_, Self>) {
match event {
MigratorEvent::ContentChanged {
Expand Down Expand Up @@ -141,84 +151,83 @@ impl ToolbarItemView for MigratorBanner {
.detach();
}

if let Some(migration_type) = self.migration_type {
cx.spawn_in(window, |this, mut cx| async move {
let message = MarkdownString(format!(
"Your {} require migration to support this version of Zed. A backup will be saved to {}.",
match migration_type {
MigrationType::Keymap => "keymap",
MigrationType::Settings => "settings",
},
match migration_type {
MigrationType::Keymap => paths::keymap_backup_file().to_string_lossy(),
MigrationType::Settings => paths::settings_backup_file().to_string_lossy(),
},
));
let parsed_markdown = cx
.background_executor()
.spawn(async move {
let file_location_directory = None;
let language_registry = None;
markdown_preview::markdown_parser::parse_markdown(
&message.0,
file_location_directory,
language_registry,
)
.await
})
.await;
this
.update(&mut cx, |this, _| {
this.message = parsed_markdown;
})
.log_err();
})
.detach();
}

return ToolbarItemLocation::Hidden;
}
}

impl Render for MigratorBanner {
fn render(&mut self, window: &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 file_type = match migration_type {
Some(MigrationType::Keymap) => "keymap",
Some(MigrationType::Settings) => "settings",
None => "",
};
let backup_file_name = self.backup_file_name();

h_flex()
.py_1()
.px_2()
.pl_2()
.pr_1()
.flex_wrap()
.justify_between()
.bg(cx.theme().status().info_background)
.bg(cx.theme().status().info_background.opacity(0.6))
.border_1()
.border_color(cx.theme().colors().border_variant)
.rounded_md()
.gap_2()
.overflow_hidden()
.child(
render_parsed_markdown(&self.message, Some(self.workspace.clone()), window, cx)
.text_ellipsis(),
)
.child(
Button::new(
SharedString::from("backup-and-migrate"),
"Backup and Migrate",
)
.style(ButtonStyle::Filled)
.on_click(move |_, _, cx| {
let fs = <dyn Fs>::global(cx);
match migration_type {
Some(MigrationType::Keymap) => {
cx.spawn(
move |_| async move { write_keymap_migration(&fs).await.ok() },
h_flex()
.gap_2()
.child(
Icon::new(IconName::Warning)
.size(IconSize::XSmall)
.color(Color::Warning),
)
.child(
h_flex()
.gap_0p5()
.child(
Label::new(format!(
"Your {} file requires migration to support this version of Zed. A backup will be saved to",
file_type
))
.color(Color::Default)
)
.detach();
}
Some(MigrationType::Settings) => {
cx.spawn(
move |_| async move { write_settings_migration(&fs).await.ok() },
.child(
div()
.px_1()
.bg(cx.theme().colors().background)
.rounded_sm()
.child(
Label::new(backup_file_name)
.buffer_font(cx)
.size(LabelSize::Small)
),
)
.detach();
)
)
.child(
Button::new("backup-and-migrate", "Backup and Migrate").on_click(
move |_, _, cx| {
let fs = <dyn Fs>::global(cx);
match migration_type {
Some(MigrationType::Keymap) => {
cx.spawn(
move |_| async move { write_keymap_migration(&fs).await.ok() },
)
.detach();
}
Some(MigrationType::Settings) => {
cx.spawn(move |_| async move {
write_settings_migration(&fs).await.ok()
})
.detach();
}
None => unreachable!(),
}
None => unreachable!(),
}
}),
},
),
)
.into_any_element()
}
Expand Down