sample.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var editor = monaco.editor.create(document.getElementById("container"), {
  2. value: [
  3. '',
  4. 'class Example {',
  5. '\tprivate m:number;',
  6. '',
  7. '\tpublic met(): string {',
  8. '\t\treturn "Hello world!";',
  9. '\t}',
  10. '}'
  11. ].join('\n'),
  12. language: "typescript"
  13. });
  14. // Explanation:
  15. // Try right clicking on an identifier or keyword => the action will be enabled (due to `tokensAtPosition`)
  16. // Try right clicking on a string => the action will be disabled (due to `tokensAtPosition`)
  17. // Try right clicking on whitespace => the action will be disabled (due to `wordAtPosition`)
  18. // Press F1 (Alt-F1 in IE) => the action will appear and run if it is enabled
  19. // Press Ctrl-F10 => the action will run if it is enabled
  20. editor.addAction({
  21. // An unique identifier of the contributed action.
  22. id: 'my-unique-id',
  23. // A label of the action that will be presented to the user.
  24. label: 'My Label!!!',
  25. // An optional array of keybindings for the action.
  26. keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10],
  27. keybindingContext: null,
  28. contextMenuGroupId: 'navigation',
  29. contextMenuOrder: 1.5,
  30. // Method that will be executed when the action is triggered.
  31. // @param editor The editor instance is passed in as a convinience
  32. run: function(ed) {
  33. alert("i'm running => " + ed.getPosition());
  34. return null;
  35. }
  36. });