sample.js 888 B

123456789101112131415161718192021222324252627282930313233
  1. var jsCode = [
  2. '"use strict";',
  3. 'function Person(age) {',
  4. ' if (age) {',
  5. ' this.age = age;',
  6. ' }',
  7. '}',
  8. 'Person.prototype.getAge = function () {',
  9. ' return this.age;',
  10. '};'
  11. ].join('\n');
  12. var editor = monaco.editor.create(document.getElementById("container"), {
  13. value: jsCode,
  14. language: "javascript"
  15. });
  16. var myCondition1 = editor.createContextKey(/*key name*/'myCondition1', /*default value*/false);
  17. var myCondition2 = editor.createContextKey(/*key name*/'myCondition2', /*default value*/false);
  18. editor.addCommand(monaco.KeyCode.Tab, function() {
  19. // services available in `ctx`
  20. alert('my command is executing!');
  21. }, 'myCondition1 && myCondition2')
  22. myCondition1.set(true);
  23. setTimeout(function() {
  24. alert('now enabling also myCondition2, try pressing Tab!');
  25. myCondition2.set(true);
  26. // you can use myCondition2.reset() to go back to the default
  27. }, 2000);