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

Add keystroke command interface #52

Open
JosiahParry opened this issue Dec 17, 2023 · 1 comment
Open

Add keystroke command interface #52

JosiahParry opened this issue Dec 17, 2023 · 1 comment

Comments

@JosiahParry
Copy link

At the moment I am trying to add cmd + enter command with a leptos app that is using monaco. It is not clear how to do this using the current API. I found an example (below) that uses quite a bit of witch craft that I cannot follow.

https://github.com/abesto/clox-rs/blob/8d6428da1f0a2253e37a003544bec1f86c544b49/web/src/main.rs#L177

@b0x-Cub3d
Copy link
Contributor

b0x-Cub3d commented Dec 27, 2023

The general way to incorporate keystrokes is by utilizing CodeEditorLink and having a closure that would do an action, i.e. getting the code from the TextModel and setting it in an emulator. Based on the code from the link:

  1. Create the closure that will do an action.
  2. Create a callback that uses the CodeEditorLink to access the Editor you're using, you'll access it via .with_editor.
  3. You create your keystroke via KeyCode and KeyMod.
  4. You create a reference to your editor(.as_ref()), and then you use that to store the command(.add_command()).
    add_command() takes three arguments which are the keybinding, the function, and the context.

And that should be it, I suggest that you look through the docs to get a better understanding of interfacing with Monaco.

Edit: I just realized that CodeEditorLink is part of interfacing with Yew, so I don't know how that works with Leptos. Hopefully with how I broke it down, you know where to go from here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants