76d1b6a5d96d0a499ca2ce09bd08077f411d635d3db86755b9326c010852d947de3a35a965d23c0ff9246094eecbc442015cf87d1590ac2b440661ad881269 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import './linesDecorations.css';
  6. import { DecorationToRender, DedupOverlay } from '../glyphMargin/glyphMargin.js';
  7. export class LinesDecorationsOverlay extends DedupOverlay {
  8. constructor(context) {
  9. super();
  10. this._context = context;
  11. const options = this._context.configuration.options;
  12. const layoutInfo = options.get(133 /* EditorOption.layoutInfo */);
  13. this._decorationsLeft = layoutInfo.decorationsLeft;
  14. this._decorationsWidth = layoutInfo.decorationsWidth;
  15. this._renderResult = null;
  16. this._context.addEventHandler(this);
  17. }
  18. dispose() {
  19. this._context.removeEventHandler(this);
  20. this._renderResult = null;
  21. super.dispose();
  22. }
  23. // --- begin event handlers
  24. onConfigurationChanged(e) {
  25. const options = this._context.configuration.options;
  26. const layoutInfo = options.get(133 /* EditorOption.layoutInfo */);
  27. this._decorationsLeft = layoutInfo.decorationsLeft;
  28. this._decorationsWidth = layoutInfo.decorationsWidth;
  29. return true;
  30. }
  31. onDecorationsChanged(e) {
  32. return true;
  33. }
  34. onFlushed(e) {
  35. return true;
  36. }
  37. onLinesChanged(e) {
  38. return true;
  39. }
  40. onLinesDeleted(e) {
  41. return true;
  42. }
  43. onLinesInserted(e) {
  44. return true;
  45. }
  46. onScrollChanged(e) {
  47. return e.scrollTopChanged;
  48. }
  49. onZonesChanged(e) {
  50. return true;
  51. }
  52. // --- end event handlers
  53. _getDecorations(ctx) {
  54. const decorations = ctx.getDecorationsInViewport();
  55. const r = [];
  56. let rLen = 0;
  57. for (let i = 0, len = decorations.length; i < len; i++) {
  58. const d = decorations[i];
  59. const linesDecorationsClassName = d.options.linesDecorationsClassName;
  60. if (linesDecorationsClassName) {
  61. r[rLen++] = new DecorationToRender(d.range.startLineNumber, d.range.endLineNumber, linesDecorationsClassName);
  62. }
  63. const firstLineDecorationClassName = d.options.firstLineDecorationClassName;
  64. if (firstLineDecorationClassName) {
  65. r[rLen++] = new DecorationToRender(d.range.startLineNumber, d.range.startLineNumber, firstLineDecorationClassName);
  66. }
  67. }
  68. return r;
  69. }
  70. prepareRender(ctx) {
  71. const visibleStartLineNumber = ctx.visibleRange.startLineNumber;
  72. const visibleEndLineNumber = ctx.visibleRange.endLineNumber;
  73. const toRender = this._render(visibleStartLineNumber, visibleEndLineNumber, this._getDecorations(ctx));
  74. const left = this._decorationsLeft.toString();
  75. const width = this._decorationsWidth.toString();
  76. const common = '" style="left:' + left + 'px;width:' + width + 'px;"></div>';
  77. const output = [];
  78. for (let lineNumber = visibleStartLineNumber; lineNumber <= visibleEndLineNumber; lineNumber++) {
  79. const lineIndex = lineNumber - visibleStartLineNumber;
  80. const classNames = toRender[lineIndex];
  81. let lineOutput = '';
  82. for (let i = 0, len = classNames.length; i < len; i++) {
  83. lineOutput += '<div class="cldr ' + classNames[i] + common;
  84. }
  85. output[lineIndex] = lineOutput;
  86. }
  87. this._renderResult = output;
  88. }
  89. render(startLineNumber, lineNumber) {
  90. if (!this._renderResult) {
  91. return '';
  92. }
  93. return this._renderResult[lineNumber - startLineNumber];
  94. }
  95. }