Skip to content

Allow querying the current mode in some way other than show_mode()? #174

@aldanor

Description

@aldanor

I've tried modifying the editor.rs example to add the very common vim pattern of mapping esc to a jk/jj/fd/etc that are pressed fast enough one after another.

It was surprisingly simple, but required querying current mode, which I couldn't find any way doing other than checking .show_mode() which feels quite hacky (but works):

        let mut tm = None;
        let esc = ['f', 'd'];
        ...
            let mut key = self.step()?;
            
            let is_insert = self.bindings.show_mode().is_some_and(|m| m == "-- INSERT --");

            if is_insert && key.get_literal_char().is_some_and(|c| c == esc[0]) {
                tm = Some(std::time::Instant::now());
            } else if is_insert
                && tm.is_some_and(|t| t.elapsed().as_millis() < 100)
                && key.get_literal_char().is_some_and(|c| c == esc[1])
            {
                self.bindings.input_key(KeyCode::Backspace.into());
                key = KeyCode::Esc.into();
            } else {
                tm = None;
            }

            self.bindings.input_key(key);
            ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions