rust-monaco icon indicating copy to clipboard operation
rust-monaco copied to clipboard

Add keystroke command interface

Open JosiahParry opened this issue 1 year ago • 1 comments

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

JosiahParry avatar Dec 17 '23 20:12 JosiahParry

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.

b0x-Cub3d avatar Dec 27 '23 04:12 b0x-Cub3d