interacting-with-the-editor-adding-a-command-to-an-editor-instance.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <!DOCTYPE html>
  2. <!-- THIS IS A GENERATED FILE VIA gulp generate-test-samples -->
  3. <html>
  4. <head>
  5. <base href="..">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  7. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  8. </head>
  9. <body>
  10. <style>
  11. /*----------------------------------------SAMPLE CSS START*/
  12. /*----------------------------------------SAMPLE CSS END*/
  13. </style>
  14. <a class="loading-opts" href="playground.generated/index.html">[&lt;&lt; BACK]</a> <br/>
  15. THIS IS A GENERATED FILE VIA gulp generate-test-samples
  16. <div id="bar" style="margin-bottom: 6px;"></div>
  17. <div style="clear:both"></div>
  18. <div id="outer-container" style="width:800px;height:450px;border: 1px solid grey">
  19. <!-- ----------------------------------------SAMPLE HTML START-->
  20. <div id="container" style="height:100%;"></div>
  21. <!-- ----------------------------------------SAMPLE HTML END-->
  22. </div>
  23. <div style="clear:both"></div>
  24. <script src="../metadata.js"></script>
  25. <script src="dev-setup.js"></script>
  26. <script>
  27. loadEditor(function() {
  28. /*----------------------------------------SAMPLE JS START*/
  29. var jsCode = [
  30. '"use strict";',
  31. 'function Person(age) {',
  32. ' if (age) {',
  33. ' this.age = age;',
  34. ' }',
  35. '}',
  36. 'Person.prototype.getAge = function () {',
  37. ' return this.age;',
  38. '};'
  39. ].join('\n');
  40. var editor = monaco.editor.create(document.getElementById("container"), {
  41. value: jsCode,
  42. language: "javascript"
  43. });
  44. var myCondition1 = editor.createContextKey(/*key name*/'myCondition1', /*default value*/false);
  45. var myCondition2 = editor.createContextKey(/*key name*/'myCondition2', /*default value*/false);
  46. editor.addCommand(monaco.KeyCode.Tab, function() {
  47. // services available in `ctx`
  48. alert('my command is executing!');
  49. }, 'myCondition1 && myCondition2')
  50. myCondition1.set(true);
  51. setTimeout(function() {
  52. alert('now enabling also myCondition2, try pressing Tab!');
  53. myCondition2.set(true);
  54. // you can use myCondition2.reset() to go back to the default
  55. }, 2000);
  56. /*----------------------------------------SAMPLE JS END*/
  57. });
  58. </script>
  59. </body>
  60. </html>