ecfb41bf53ac00d3c993e3bf28bee1773ec2116d52728605f57a5541a823b2fab95bdf2d1f5150335166074492f20b26469487747d3218e3bdca635b494742 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 { Disposable } from '../../../../base/common/lifecycle.js';
  6. import { registerEditorContribution } from '../../../browser/editorExtensions.js';
  7. import { Range } from '../../../common/core/range.js';
  8. import { ColorDecorationInjectedTextMarker } from './colorDetector.js';
  9. import { ColorHoverParticipant } from './colorHoverParticipant.js';
  10. import { ModesHoverController } from '../../hover/browser/hover.js';
  11. import { HoverParticipantRegistry } from '../../hover/browser/hoverTypes.js';
  12. export class ColorContribution extends Disposable {
  13. constructor(_editor) {
  14. super();
  15. this._editor = _editor;
  16. this._register(_editor.onMouseDown((e) => this.onMouseDown(e)));
  17. }
  18. dispose() {
  19. super.dispose();
  20. }
  21. onMouseDown(mouseEvent) {
  22. const target = mouseEvent.target;
  23. if (target.type !== 6 /* MouseTargetType.CONTENT_TEXT */) {
  24. return;
  25. }
  26. if (!target.detail.injectedText) {
  27. return;
  28. }
  29. if (target.detail.injectedText.options.attachedData !== ColorDecorationInjectedTextMarker) {
  30. return;
  31. }
  32. if (!target.range) {
  33. return;
  34. }
  35. const hoverController = this._editor.getContribution(ModesHoverController.ID);
  36. if (!hoverController) {
  37. return;
  38. }
  39. if (!hoverController.isColorPickerVisible()) {
  40. const range = new Range(target.range.startLineNumber, target.range.startColumn + 1, target.range.endLineNumber, target.range.endColumn + 1);
  41. hoverController.showContentHover(range, 1 /* HoverStartMode.Immediate */, false);
  42. }
  43. }
  44. }
  45. ColorContribution.ID = 'editor.contrib.colorContribution'; // ms
  46. registerEditorContribution(ColorContribution.ID, ColorContribution);
  47. HoverParticipantRegistry.register(ColorHoverParticipant);