diff --git a/assets/default-settings.json b/assets/default-settings.json index 45032b4288c37d7f247d40be5234c9db1664200f..2417d0f5d437f44957aad24128521c4899a5a678 100644 --- a/assets/default-settings.json +++ b/assets/default-settings.json @@ -1,17 +1,81 @@ { + // The name of the Zed theme to use for the UI "theme": "cave-dark", + + // The name of a font to use for rendering text in the editor "buffer_font_family": "Zed Mono", + + // The default font size for text in the editor "buffer_font_size": 15, + + // Whether to enable vim modes and key bindings "vim_mode": false, + + // Whether to show the informational hover box when moving the mouse + // over symbols in the editor. "hover_popover_enabled": true, + + // Whether new projects should start out 'online'. Online projects + // appear in the contacts panel under your name, so that your contacts + // can see which projects you are working on. Regardless of this + // setting, projects keep their last online status when you reopen them. "projects_online_by_default": true, + + // Whether to use language servers to provide code intelligence. "enable_language_server": true, + + // When to automatically save edited buffers. This setting can + // take four values. + // + // 1. Never automatically save: + // "autosave": "off", + // 2. Save when changing focus away from the Zed window: + // "autosave": "on_window_change", + // 3. Save when changing focus away from a specific buffer: + // "autosave": "on_focus_change", + // 4. Save when idle for a certain amount of time: + // "autosave": { "after_delay": {"milliseconds": 500} }, "autosave": "off", + + // How to auto-format modified buffers when saving them. This + // setting can take three values: + // + // 1. Don't format code + // "format_on_save": "off" + // 2. Format code using the current language server: + // "format_on_save": "language_server" + // 3. Format code using an external command: + // "format_on_save": { + // "external": { + // "command": "sed", + // "arguments": ["-e", "s/ *$//"] + // } + // }, "format_on_save": "language_server", - "preferred_line_length": 80, + + // How to soft-wrap long lines of text. This setting can take + // three values: + // + // 1. Do not soft wrap. + // "soft_wrap": "none", + // 2. Soft wrap lines that overflow the editor: + // "soft_wrap": "editor_width", + // 2. Soft wrap lines at the preferred line length + // "soft_wrap": "preferred_line_length", "soft_wrap": "none", + + // The column at which to soft-wrap lines, for buffers where soft-wrap + // is enabled. + "preferred_line_length": 80, + + // Whether to indent lines using tab characters, as opposed to multiple + // spaces. "hard_tabs": false, + + // How many columns a tab should occupy. "tab_size": 4, + + // Different settings for specific languages. "languages": { "Plain Text": { "soft_wrap": "preferred_line_length" diff --git a/crates/zed/src/menus.rs b/crates/zed/src/menus.rs index a53a44fa8d7a31a2e62ed10318e3a10c674a3e97..d4d9b401e652218858e451aea2d29258a875f585 100644 --- a/crates/zed/src/menus.rs +++ b/crates/zed/src/menus.rs @@ -26,6 +26,10 @@ pub fn menus() -> Vec> { name: "Open Key Bindings", action: Box::new(super::OpenKeymap), }, + MenuItem::Action { + name: "Open Default Settings", + action: Box::new(super::OpenDefaultSettings), + }, MenuItem::Action { name: "Open Default Key Bindings", action: Box::new(super::OpenDefaultKeymap), diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index d78cb9c9a234f02c1698e3e306dd79040a86c4b5..1bfa75b9205bc5c8106749539ddef4040b7c6a93 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -52,6 +52,7 @@ actions!( DebugElements, OpenSettings, OpenKeymap, + OpenDefaultSettings, OpenDefaultKeymap, IncreaseBufferFontSize, DecreaseBufferFontSize, @@ -111,27 +112,27 @@ pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { cx.add_action({ let app_state = app_state.clone(); move |workspace: &mut Workspace, _: &OpenDefaultKeymap, cx: &mut ViewContext| { - workspace.with_local_workspace(cx, app_state.clone(), |workspace, cx| { - let project = workspace.project().clone(); - let buffer = project.update(cx, |project, cx| { - let text = Assets::get("keymaps/default.json").unwrap().data; - let text = str::from_utf8(text.as_ref()).unwrap(); - project - .create_buffer(text, project.languages().get_language("JSON"), cx) - .expect("creating buffers on a local workspace always succeeds") - }); - let buffer = cx.add_model(|cx| { - MultiBuffer::singleton(buffer, cx).with_title("Default Key Bindings".into()) - }); - workspace.add_item( - Box::new( - cx.add_view(|cx| { - Editor::for_multibuffer(buffer, Some(project.clone()), cx) - }), - ), - cx, - ); - }); + open_bundled_config_file( + workspace, + app_state.clone(), + "keymaps/default.json", + "Default Key Bindings", + cx, + ); + } + }); + cx.add_action({ + let app_state = app_state.clone(); + move |workspace: &mut Workspace, + _: &OpenDefaultSettings, + cx: &mut ViewContext| { + open_bundled_config_file( + workspace, + app_state.clone(), + "default-settings.json", + "Default Settings", + cx, + ); } }); cx.add_action( @@ -386,6 +387,30 @@ fn open_config_file( .detach_and_log_err(cx) } +fn open_bundled_config_file( + workspace: &mut Workspace, + app_state: Arc, + asset_path: &'static str, + title: &str, + cx: &mut ViewContext, +) { + workspace.with_local_workspace(cx, app_state.clone(), |workspace, cx| { + let project = workspace.project().clone(); + let buffer = project.update(cx, |project, cx| { + let text = Assets::get(asset_path).unwrap().data; + let text = str::from_utf8(text.as_ref()).unwrap(); + project + .create_buffer(text, project.languages().get_language("JSON"), cx) + .expect("creating buffers on a local workspace always succeeds") + }); + let buffer = cx.add_model(|cx| MultiBuffer::singleton(buffer, cx).with_title(title.into())); + workspace.add_item( + Box::new(cx.add_view(|cx| Editor::for_multibuffer(buffer, Some(project.clone()), cx))), + cx, + ); + }); +} + #[cfg(test)] mod tests { use super::*;