sample.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 => the action will appear and run if it is enabled
  16. // Press Ctrl-F10 => the action will run if it is enabled
  17. // Press Chord Ctrl-K, Ctrl-M => the action will run if it is enabled
  18. editor.addAction({
  19. // An unique identifier of the contributed action.
  20. id: 'my-unique-id',
  21. // A label of the action that will be presented to the user.
  22. label: 'My Label!!!',
  23. // An optional array of keybindings for the action.
  24. keybindings: [
  25. monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10,
  26. // chord
  27. monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyK, monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyM)
  28. ],
  29. // A precondition for this action.
  30. precondition: null,
  31. // A rule to evaluate on top of the precondition in order to dispatch the keybindings.
  32. keybindingContext: null,
  33. contextMenuGroupId: 'navigation',
  34. contextMenuOrder: 1.5,
  35. // Method that will be executed when the action is triggered.
  36. // @param editor The editor instance is passed in as a convenience
  37. run: function(ed) {
  38. alert("i'm running => " + ed.getPosition());
  39. return null;
  40. }
  41. });