Closed Cobertos closed 3 years ago
e.preventDefault();
prevents the default browser action. In the case of S
, the default browser action is to create an input
event for S
and type it in the <textarea>
we use for input. So preventing default on S
leads to nothing being typed in the <textarea>
, thus we don't receive an input
event, thus nothing happens.
In the case of Tab
, the default browser action is to move the focus to the next HTML element. This is prevented by your code, but all our keybindings that also run on Tab
are not prevented. This is because e.preventDefault()
is a browser concept, and not a Monaco Editor concept. Here is an example that shows how you can override Tab. The sample is more complicated, it also shows how you can dynamically turn on/off this override --> https://microsoft.github.io/monaco-editor/playground.html#interacting-with-the-editor-adding-a-command-to-an-editor-instance
When using
e.preventDefault()
on an event fromEditor#onKeyDown
, it doesn't seem to work when the key was aTab
key.Example (prevents both Tab and 'S', while 'S' never prints, it does indent on Tab): https://codepen.io/cobertos/pen/qBXKLpO?editors=0010
Code: