sample.js 1.5 KB

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