interacting-with-the-editor-adding-an-action-to-an-editor-instance.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <!-- THIS IS A GENERATED FILE VIA `npm run simpleserver` -->
  3. <html>
  4. <head>
  5. <base href="..">
  6. <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  7. </head>
  8. <body>
  9. <style>
  10. /*----------------------------------------SAMPLE CSS START*/
  11. /*----------------------------------------SAMPLE CSS END*/
  12. </style>
  13. <a class="loading-opts" href="playground.generated/index.html">[&lt;&lt; BACK]</a> <br/>
  14. THIS IS A GENERATED FILE VIA `npm run simpleserver`
  15. <div id="bar" style="margin-bottom: 6px;"></div>
  16. <div style="clear:both"></div>
  17. <div id="outer-container" style="width:800px;height:450px;border: 1px solid grey">
  18. <!-- ----------------------------------------SAMPLE HTML START-->
  19. <div id="container" style="height: 100%"></div>
  20. <!-- ----------------------------------------SAMPLE HTML END-->
  21. </div>
  22. <div style="clear:both"></div>
  23. <script src="../../metadata.js"></script>
  24. <script src="dev-setup.js"></script>
  25. <script>
  26. loadEditor(function() {
  27. /*----------------------------------------SAMPLE JS START*/
  28. var editor = monaco.editor.create(document.getElementById('container'), {
  29. value: [
  30. '',
  31. 'class Example {',
  32. '\tprivate m:number;',
  33. '',
  34. '\tpublic met(): string {',
  35. '\t\treturn "Hello world!";',
  36. '\t}',
  37. '}'
  38. ].join('\n'),
  39. language: 'typescript'
  40. });
  41. // Explanation:
  42. // Press F1 => the action will appear and run if it is enabled
  43. // Press Ctrl-F10 => the action will run if it is enabled
  44. // Press Chord Ctrl-K, Ctrl-M => the action will run if it is enabled
  45. editor.addAction({
  46. // An unique identifier of the contributed action.
  47. id: 'my-unique-id',
  48. // A label of the action that will be presented to the user.
  49. label: 'My Label!!!',
  50. // An optional array of keybindings for the action.
  51. keybindings: [
  52. monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10,
  53. // chord
  54. monaco.KeyMod.chord(
  55. monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyK,
  56. monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyM
  57. )
  58. ],
  59. // A precondition for this action.
  60. precondition: null,
  61. // A rule to evaluate on top of the precondition in order to dispatch the keybindings.
  62. keybindingContext: null,
  63. contextMenuGroupId: 'navigation',
  64. contextMenuOrder: 1.5,
  65. // Method that will be executed when the action is triggered.
  66. // @param editor The editor instance is passed in as a convenience
  67. run: function (ed) {
  68. alert("i'm running => " + ed.getPosition());
  69. }
  70. });
  71. /*----------------------------------------SAMPLE JS END*/
  72. });
  73. </script>
  74. </body>
  75. </html>