Repository: lapce/lapce
File: lapce-data/src/keypress.rs (Rust)

Code before:
            "right" => ArrowRight,
            "left" => ArrowLeft,
            "del" => Delete,

            _ => return None,
        })
    }

    fn get_keypress(key: &str) -> Vec<KeyPress> {
        let mut keypresses = Vec::new();
        for k in key.split(' ') {
            let mut mods = Modifiers::default();

            let parts = k.split('+').collect::<Vec<&str>>();
            if parts.is_empty() {
                continue;
            }

            let last_part = parts[parts.len() - 1];
            let key =
                KeyPressData::map_str_to_key(last_part.to_lowercase().as_str());
            let key = if let Some(key) = key {
                key
            } else {
                // Skip past unrecognized key definitions
                eprintln!("Unrecognized key: {}", last_part);
                continue;
            };

            for part in &parts[..parts.len() - 1] {
                match part.to_lowercase().as_ref() {
                    "ctrl" => mods.set(Modifiers::CONTROL, true),
                    "meta" => mods.set(Modifiers::META, true),
                    "shift" => mods.set(Modifiers::SHIFT, true),
                    "alt" => mods.set(Modifiers::ALT, true),
                    _ => (),
                }
            }

            let keypress = KeyPress { mods, key };
            keypresses.push(keypress);
        }
        keypresses
    }

    fn get_keymap(toml_keymap: &toml::Value, modal: bool) -> Result<KeyMap> {
        let key = toml_keymap
            .get("key")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow!("no key in keymap"))?;


Review comment (bug):
👍 
Nice for debugging.
Do you think its worth ticketing up introducing a logging library, or is standard prints probably enough for an IDE?

Code after:
            "right" => ArrowRight,
            "left" => ArrowLeft,
            "del" => Delete,

            _ => return None,
        })
    }

    fn get_keypress(key: &str) -> Vec<KeyPress> {
        let mut keypresses = Vec::new();
        for k in key.split(' ') {
            let mut mods = Modifiers::default();

            let parts = k.split('+').collect::<Vec<&str>>();
            if parts.is_empty() {
                continue;
            }

            let last_part = parts[parts.len() - 1];
            let key =
                KeyPressData::map_str_to_key(last_part.to_lowercase().as_str());
            let key = if let Some(key) = key {
                key
            } else {
                // Skip past unrecognized key definitions
                log::warn!("Unrecognized key: {}", last_part);
                continue;
            };

            for part in &parts[..parts.len() - 1] {
                match part.to_lowercase().as_ref() {
                    "ctrl" => mods.set(Modifiers::CONTROL, true),
                    "meta" => mods.set(Modifiers::META, true),
                    "shift" => mods.set(Modifiers::SHIFT, true),
                    "alt" => mods.set(Modifiers::ALT, true),
                    _ => (),
                }
            }

            let keypress = KeyPress { mods, key };
            keypresses.push(keypress);
        }
        keypresses
    }

    fn get_keymap(toml_keymap: &toml::Value, modal: bool) -> Result<KeyMap> {
        let key = toml_keymap
            .get("key")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow!("no key in keymap"))?;