1
0

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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 editor = monaco.editor.create(document.getElementById("container"), {
  30. value: [
  31. '',
  32. 'class Example {',
  33. '\tprivate m:number;',
  34. '',
  35. '\tpublic met(): string {',
  36. '\t\treturn "Hello world!";',
  37. '\t}',
  38. '}'
  39. ].join('\n'),
  40. language: "typescript"
  41. });
  42. // Explanation:
  43. // Try right clicking on an identifier or keyword => the action will be enabled (due to `tokensAtPosition`)
  44. // Try right clicking on a string => the action will be disabled (due to `tokensAtPosition`)
  45. // Try right clicking on whitespace => the action will be disabled (due to `wordAtPosition`)
  46. // Press F1 (Alt-F1 in IE) => the action will appear and run if it is enabled
  47. // Press Ctrl-F10 => the action will run if it is enabled
  48. editor.addAction({
  49. // An unique identifier of the contributed action.
  50. id: 'my-unique-id',
  51. // A label of the action that will be presented to the user.
  52. label: 'My Label!!!',
  53. // An optional array of keybindings for the action.
  54. keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10],
  55. keybindingContext: null,
  56. // Control if the action should show up in the context menu and where.
  57. // Built-in groups:
  58. // 1_goto/* => e.g. 1_goto/1_peekDefinition
  59. // 2_change/* => e.g. 2_change/2_format
  60. // 3_edit/* => e.g. 3_edit/1_copy
  61. // 4_tools/* => e.g. 4_tools/1_commands
  62. // You can also create your own group.
  63. // Defaults to null (don't show in context menu).
  64. contextMenuGroupId: '2_change/2_bla',
  65. // Method that will be executed when the action is triggered.
  66. // @param editor The editor instance is passed in as a convinience
  67. run: function(ed) {
  68. alert("i'm running => " + ed.getPosition());
  69. return null;
  70. },
  71. // Optional enablement conditions. All members are optional
  72. enablement: {
  73. // The action is enabled only if text in the editor is focused (e.g. blinking cursor).
  74. // Warning: This condition will be disabled if the action is marked to be displayed in the context menu
  75. // Defaults to false.
  76. textFocus: true,
  77. // The action is enabled only if the editor or its widgets have focus (e.g. focus is in find widget).
  78. // Defaults to false.
  79. //widgetFocus: true,
  80. // The action is enabled only if the editor is not in read only mode.
  81. // Defaults to false.
  82. //writeableEditor: true,
  83. // The action is enabled only if the cursor position is over a word (i.e. not whitespace).
  84. // Defaults to false.
  85. wordAtPosition: true,
  86. // The action is enabled only if the cursor position is over tokens of a certain kind.
  87. // Defaults to no tokens required.
  88. tokensAtPosition: ['identifier', '', 'keyword'],
  89. }
  90. });
  91. /*----------------------------------------SAMPLE CSS END*/
  92. });
  93. </script>
  94. </body>
  95. </html>