684b24e98836e0c3eb3d08480d9067669cc61f6bea031964eed58931a7d873fa5ba36fcdd934686be6fb0eec8a5d29ec80a9db9b7ed129e8253921922276b4 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 './scrollDecoration.css';
  6. import { createFastDomNode } from '../../../../base/browser/fastDomNode.js';
  7. import { ViewPart } from '../../view/viewPart.js';
  8. import { scrollbarShadow } from '../../../../platform/theme/common/colorRegistry.js';
  9. import { registerThemingParticipant } from '../../../../platform/theme/common/themeService.js';
  10. export class ScrollDecorationViewPart extends ViewPart {
  11. constructor(context) {
  12. super(context);
  13. this._scrollTop = 0;
  14. this._width = 0;
  15. this._updateWidth();
  16. this._shouldShow = false;
  17. const options = this._context.configuration.options;
  18. const scrollbar = options.get(94 /* EditorOption.scrollbar */);
  19. this._useShadows = scrollbar.useShadows;
  20. this._domNode = createFastDomNode(document.createElement('div'));
  21. this._domNode.setAttribute('role', 'presentation');
  22. this._domNode.setAttribute('aria-hidden', 'true');
  23. }
  24. dispose() {
  25. super.dispose();
  26. }
  27. _updateShouldShow() {
  28. const newShouldShow = (this._useShadows && this._scrollTop > 0);
  29. if (this._shouldShow !== newShouldShow) {
  30. this._shouldShow = newShouldShow;
  31. return true;
  32. }
  33. return false;
  34. }
  35. getDomNode() {
  36. return this._domNode;
  37. }
  38. _updateWidth() {
  39. const options = this._context.configuration.options;
  40. const layoutInfo = options.get(133 /* EditorOption.layoutInfo */);
  41. if (layoutInfo.minimap.renderMinimap === 0 || (layoutInfo.minimap.minimapWidth > 0 && layoutInfo.minimap.minimapLeft === 0)) {
  42. this._width = layoutInfo.width;
  43. }
  44. else {
  45. this._width = layoutInfo.width - layoutInfo.verticalScrollbarWidth;
  46. }
  47. }
  48. // --- begin event handlers
  49. onConfigurationChanged(e) {
  50. const options = this._context.configuration.options;
  51. const scrollbar = options.get(94 /* EditorOption.scrollbar */);
  52. this._useShadows = scrollbar.useShadows;
  53. this._updateWidth();
  54. this._updateShouldShow();
  55. return true;
  56. }
  57. onScrollChanged(e) {
  58. this._scrollTop = e.scrollTop;
  59. return this._updateShouldShow();
  60. }
  61. // --- end event handlers
  62. prepareRender(ctx) {
  63. // Nothing to read
  64. }
  65. render(ctx) {
  66. this._domNode.setWidth(this._width);
  67. this._domNode.setClassName(this._shouldShow ? 'scroll-decoration' : '');
  68. }
  69. }
  70. registerThemingParticipant((theme, collector) => {
  71. const shadow = theme.getColor(scrollbarShadow);
  72. if (shadow) {
  73. collector.addRule(`.monaco-editor .scroll-decoration { box-shadow: ${shadow} 0 6px 6px -6px inset; }`);
  74. }
  75. });