sample.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // Press F1 (Alt-F1 in IE) => the action will appear and run if it is enabled
  16. // Press Ctrl-F10 => the action will run if it is enabled
  17. editor.addAction({
  18. // An unique identifier of the contributed action.
  19. id: 'my-unique-id',
  20. // A label of the action that will be presented to the user.
  21. label: 'My Label!!!',
  22. // An optional array of keybindings for the action.
  23. keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10],
  24. // A precondition for this action.
  25. precondition: null,
  26. // A rule to evaluate on top of the precondition in order to dispatch the keybindings.
  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. });