zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
50.32k stars 3.1k forks source link

If no keymap.json exists, populate the buffer with an empty but valid skeleton #4940

Closed jansol closed 3 months ago

jansol commented 1 year ago

Check for existing issues

Describe the feature

Currently creating custom keybindings requires a bit of inferring the file structure from the default bindings if there is no keymap.json yet. This could be improved easily by having zed fill out the buffer for a new keymap.json with the basic file structure and some helpful comments.

If applicable, add mockups / screenshots to help present your vision of the feature

[
    {
        "bindings": {
            // global bindings go here
            // "cmd-0": "zed::ResetBufferFontSize",
        }
    },
    {
        "context": "Editor",
        "bindings": {
            // editor-specific bindings go here
        }
    },
    {
        "context": "Pane",
        "bindings": {
        }
    },
    {
        "context": "Workspace",
        "bindings": {
        }
    }
]
Eiji7 commented 6 months ago

I was thinking about creating a similar bug report, but found this one. By default the ~/.config/zed/keymap.json file is not created. This or empty file results with a:

[2024-04-28T02:05:27+03:00 ERROR util] crates/zed/src/zed.rs:637: EOF while parsing a value at line 1 column 0

The error is located in pub fn handle_keymap_file_changes(mut user_keymap_file_rx: mpsc::UnboundedReceiver<String>, cx: &mut AppContext,) in file src/zed.rs in zed crate.

The &user_keymap_content is empty "" causing a parsing error.

This could be fixed by:

  1. Fixing KeymapFile::parse(&user_keymap_content) which should handle empty values properly
  2. Adding a simple if condition checking if &user_keymap_content is empty
  3. Generating a default valid and empty file with [] contents
  4. Generating a base keymap file template as mentioned above
JosephTLyons commented 3 months ago

Zed now does add the following when opening the settings view for the first time:

// Zed settings
//
// For information on how to configure Zed, see the Zed
// documentation: https://zed.dev/docs/configuring-zed
//
// To see all of Zed's default settings without changing your
// custom settings, run the `zed: Open Default Settings` command
// from the command palette
{
  "ui_font_size": 16,
  "buffer_font_size": 16,
  "theme": {
    "mode": "system",
    "light": "One Light",
    "dark": "One Dark"
  }
}

It doesn't add a lot, but it explains how to find more options, so I think this issue can be closed.