a456606b148f72fd18d265766e6b95037857f77003013158039084e34d4bad8b322ed84fa9f4bcb3329a8e3045fc61e2fbe7c43a94d856e51fd7deab797de1 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 { createFastDomNode } from '../../../../base/browser/fastDomNode.js';
  6. import './blockDecorations.css';
  7. import { ViewPart } from '../../view/viewPart.js';
  8. export class BlockDecorations extends ViewPart {
  9. constructor(context) {
  10. super(context);
  11. this.blocks = [];
  12. this.contentWidth = -1;
  13. this.domNode = createFastDomNode(document.createElement('div'));
  14. this.domNode.setAttribute('role', 'presentation');
  15. this.domNode.setAttribute('aria-hidden', 'true');
  16. this.domNode.setClassName('blockDecorations-container');
  17. this.update();
  18. }
  19. update() {
  20. let didChange = false;
  21. const options = this._context.configuration.options;
  22. const layoutInfo = options.get(133 /* EditorOption.layoutInfo */);
  23. const newContentWidth = layoutInfo.contentWidth - layoutInfo.verticalScrollbarWidth;
  24. if (this.contentWidth !== newContentWidth) {
  25. this.contentWidth = newContentWidth;
  26. didChange = true;
  27. }
  28. return didChange;
  29. }
  30. dispose() {
  31. super.dispose();
  32. }
  33. // --- begin event handlers
  34. onConfigurationChanged(e) {
  35. return this.update();
  36. }
  37. onScrollChanged(e) {
  38. return e.scrollTopChanged || e.scrollLeftChanged;
  39. }
  40. onDecorationsChanged(e) {
  41. return true;
  42. }
  43. onZonesChanged(e) {
  44. return true;
  45. }
  46. // --- end event handlers
  47. prepareRender(ctx) {
  48. // Nothing to read
  49. }
  50. render(ctx) {
  51. let count = 0;
  52. const decorations = ctx.getDecorationsInViewport();
  53. for (const decoration of decorations) {
  54. if (!decoration.options.blockClassName) {
  55. continue;
  56. }
  57. let block = this.blocks[count];
  58. if (!block) {
  59. block = this.blocks[count] = createFastDomNode(document.createElement('div'));
  60. this.domNode.appendChild(block);
  61. }
  62. const top = ctx.getVerticalOffsetForLineNumber(decoration.range.startLineNumber);
  63. // See https://github.com/microsoft/vscode/pull/152740#discussion_r902661546
  64. const bottom = ctx.getVerticalOffsetForLineNumber(decoration.range.endLineNumber + 1);
  65. block.setClassName('blockDecorations-block ' + decoration.options.blockClassName);
  66. block.setLeft(ctx.scrollLeft);
  67. block.setWidth(this.contentWidth);
  68. block.setTop(top);
  69. block.setHeight(bottom - top);
  70. count++;
  71. }
  72. for (let i = count; i < this.blocks.length; i++) {
  73. this.blocks[i].domNode.remove();
  74. }
  75. this.blocks.length = count;
  76. }
  77. }