0b371cf8c146cc89d71612b7665415fade18f7a745683e88cf0079a868eb4a7311f9b551c537c08513e5697150ca4eca05b2f1e9f26a2c32ebda8458921569 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 { ViewEventHandler } from '../../common/viewEventHandler.js';
  6. export class ViewPart extends ViewEventHandler {
  7. constructor(context) {
  8. super();
  9. this._context = context;
  10. this._context.addEventHandler(this);
  11. }
  12. dispose() {
  13. this._context.removeEventHandler(this);
  14. super.dispose();
  15. }
  16. }
  17. export class PartFingerprints {
  18. static write(target, partId) {
  19. target.setAttribute('data-mprt', String(partId));
  20. }
  21. static read(target) {
  22. const r = target.getAttribute('data-mprt');
  23. if (r === null) {
  24. return 0 /* PartFingerprint.None */;
  25. }
  26. return parseInt(r, 10);
  27. }
  28. static collect(child, stopAt) {
  29. const result = [];
  30. let resultLen = 0;
  31. while (child && child !== document.body) {
  32. if (child === stopAt) {
  33. break;
  34. }
  35. if (child.nodeType === child.ELEMENT_NODE) {
  36. result[resultLen++] = this.read(child);
  37. }
  38. child = child.parentElement;
  39. }
  40. const r = new Uint8Array(resultLen);
  41. for (let i = 0; i < resultLen; i++) {
  42. r[i] = result[resultLen - i - 1];
  43. }
  44. return r;
  45. }
  46. }