sample.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. monaco.languages.register({
  2. id: 'foldLanguage'
  3. });
  4. var value = `1. Hit F1 to bring up the Command Palette
  5. 2. Type 'fold'
  6. 3. Choose 'Fold All Block Comments' or 'Fold All Regions'
  7. 5. comment1
  8. 6. comment1
  9. 7. comment1
  10. 9. unfoldable text
  11. 10. unfoldable text
  12. 11. unfoldable text
  13. 13. comment2
  14. 14. comment2
  15. 15. comment2
  16. 16. comment2
  17. 17. comment2
  18. 19. foldable text
  19. 20. foldable text
  20. 21. foldable text
  21. 23. region1
  22. 24. region1
  23. 25. region1
  24. 27. region2
  25. 28. region2
  26. 29. region2`;
  27. monaco.editor.create(document.getElementById('container'), {
  28. value: value,
  29. language: 'foldLanguage'
  30. });
  31. monaco.languages.registerFoldingRangeProvider('foldLanguage', {
  32. provideFoldingRanges: function (model, context, token) {
  33. return [
  34. // comment1
  35. {
  36. start: 5,
  37. end: 7,
  38. kind: monaco.languages.FoldingRangeKind.Comment
  39. },
  40. // comment2
  41. {
  42. start: 13,
  43. end: 17,
  44. kind: monaco.languages.FoldingRangeKind.Comment
  45. },
  46. // foldable text
  47. {
  48. start: 19,
  49. end: 21
  50. },
  51. // region1
  52. {
  53. start: 23,
  54. end: 25,
  55. kind: monaco.languages.FoldingRangeKind.Region
  56. },
  57. // region2
  58. {
  59. start: 27,
  60. end: 29,
  61. kind: monaco.languages.FoldingRangeKind.Region
  62. }
  63. ];
  64. }
  65. });