8944dc8b9006d19b117ae9b226cd2bbe56f5c73b704f5cb9e4842616d3b5bafda5a4dc92b2eec977d37bb3c5ae7c824ebd509f335aa7d2c3384fd0ae946106 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 { ViewPart } from '../../view/viewPart.js';
  7. export class Margin extends ViewPart {
  8. constructor(context) {
  9. super(context);
  10. const options = this._context.configuration.options;
  11. const layoutInfo = options.get(133 /* EditorOption.layoutInfo */);
  12. this._canUseLayerHinting = !options.get(28 /* EditorOption.disableLayerHinting */);
  13. this._contentLeft = layoutInfo.contentLeft;
  14. this._glyphMarginLeft = layoutInfo.glyphMarginLeft;
  15. this._glyphMarginWidth = layoutInfo.glyphMarginWidth;
  16. this._domNode = createFastDomNode(document.createElement('div'));
  17. this._domNode.setClassName(Margin.OUTER_CLASS_NAME);
  18. this._domNode.setPosition('absolute');
  19. this._domNode.setAttribute('role', 'presentation');
  20. this._domNode.setAttribute('aria-hidden', 'true');
  21. this._glyphMarginBackgroundDomNode = createFastDomNode(document.createElement('div'));
  22. this._glyphMarginBackgroundDomNode.setClassName(Margin.CLASS_NAME);
  23. this._domNode.appendChild(this._glyphMarginBackgroundDomNode);
  24. }
  25. dispose() {
  26. super.dispose();
  27. }
  28. getDomNode() {
  29. return this._domNode;
  30. }
  31. // --- begin event handlers
  32. onConfigurationChanged(e) {
  33. const options = this._context.configuration.options;
  34. const layoutInfo = options.get(133 /* EditorOption.layoutInfo */);
  35. this._canUseLayerHinting = !options.get(28 /* EditorOption.disableLayerHinting */);
  36. this._contentLeft = layoutInfo.contentLeft;
  37. this._glyphMarginLeft = layoutInfo.glyphMarginLeft;
  38. this._glyphMarginWidth = layoutInfo.glyphMarginWidth;
  39. return true;
  40. }
  41. onScrollChanged(e) {
  42. return super.onScrollChanged(e) || e.scrollTopChanged;
  43. }
  44. // --- end event handlers
  45. prepareRender(ctx) {
  46. // Nothing to read
  47. }
  48. render(ctx) {
  49. this._domNode.setLayerHinting(this._canUseLayerHinting);
  50. this._domNode.setContain('strict');
  51. const adjustedScrollTop = ctx.scrollTop - ctx.bigNumbersDelta;
  52. this._domNode.setTop(-adjustedScrollTop);
  53. const height = Math.min(ctx.scrollHeight, 1000000);
  54. this._domNode.setHeight(height);
  55. this._domNode.setWidth(this._contentLeft);
  56. this._glyphMarginBackgroundDomNode.setLeft(this._glyphMarginLeft);
  57. this._glyphMarginBackgroundDomNode.setWidth(this._glyphMarginWidth);
  58. this._glyphMarginBackgroundDomNode.setHeight(height);
  59. }
  60. }
  61. Margin.CLASS_NAME = 'glyph-margin';
  62. Margin.OUTER_CLASS_NAME = 'margin';