@xterm/xterm 5.6.0-beta.9 → 5.6.0-beta.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +9 -3
  2. package/css/xterm.css +71 -4
  3. package/lib/xterm.js +1 -1
  4. package/lib/xterm.js.map +1 -1
  5. package/lib/xterm.mjs +53 -0
  6. package/lib/xterm.mjs.map +7 -0
  7. package/package.json +43 -33
  8. package/src/browser/AccessibilityManager.ts +53 -25
  9. package/src/browser/{Terminal.ts → CoreBrowserTerminal.ts} +139 -148
  10. package/src/browser/Linkifier.ts +26 -14
  11. package/src/browser/LocalizableStrings.ts +15 -4
  12. package/src/browser/{Types.d.ts → Types.ts} +67 -15
  13. package/src/browser/Viewport.ts +143 -370
  14. package/src/browser/decorations/BufferDecorationRenderer.ts +14 -9
  15. package/src/browser/decorations/OverviewRulerRenderer.ts +40 -44
  16. package/src/browser/input/CompositionHelper.ts +2 -1
  17. package/src/browser/public/Terminal.ts +25 -19
  18. package/src/browser/renderer/dom/DomRenderer.ts +19 -14
  19. package/src/browser/renderer/dom/DomRendererRowFactory.ts +35 -15
  20. package/src/browser/renderer/shared/CharAtlasCache.ts +3 -2
  21. package/src/browser/renderer/shared/CharAtlasUtils.ts +6 -1
  22. package/src/browser/renderer/shared/CustomGlyphs.ts +6 -0
  23. package/src/browser/renderer/shared/DevicePixelObserver.ts +1 -2
  24. package/src/browser/renderer/shared/TextureAtlas.ts +45 -12
  25. package/src/browser/renderer/shared/{Types.d.ts → Types.ts} +7 -6
  26. package/src/browser/services/CharSizeService.ts +6 -6
  27. package/src/browser/services/CoreBrowserService.ts +15 -15
  28. package/src/browser/services/LinkProviderService.ts +2 -2
  29. package/src/browser/services/RenderService.ts +20 -20
  30. package/src/browser/services/SelectionService.ts +8 -8
  31. package/src/browser/services/Services.ts +13 -13
  32. package/src/browser/services/ThemeService.ts +19 -58
  33. package/src/browser/shared/Constants.ts +8 -0
  34. package/src/common/CircularList.ts +5 -5
  35. package/src/common/CoreTerminal.ts +35 -41
  36. package/src/common/InputHandler.ts +63 -51
  37. package/src/common/{Types.d.ts → Types.ts} +13 -17
  38. package/src/common/buffer/Buffer.ts +15 -7
  39. package/src/common/buffer/BufferReflow.ts +9 -6
  40. package/src/common/buffer/BufferSet.ts +5 -5
  41. package/src/common/buffer/Marker.ts +4 -4
  42. package/src/common/buffer/{Types.d.ts → Types.ts} +2 -2
  43. package/src/common/input/WriteBuffer.ts +3 -3
  44. package/src/common/parser/EscapeSequenceParser.ts +4 -4
  45. package/src/common/public/BufferNamespaceApi.ts +3 -3
  46. package/src/common/services/BufferService.ts +7 -7
  47. package/src/common/services/CoreMouseService.ts +5 -3
  48. package/src/common/services/CoreService.ts +8 -6
  49. package/src/common/services/DecorationService.ts +8 -9
  50. package/src/common/services/InstantiationService.ts +1 -1
  51. package/src/common/services/LogService.ts +2 -2
  52. package/src/common/services/OptionsService.ts +7 -6
  53. package/src/common/services/ServiceRegistry.ts +1 -1
  54. package/src/common/services/Services.ts +26 -17
  55. package/src/common/services/UnicodeService.ts +2 -2
  56. package/src/vs/base/browser/browser.ts +141 -0
  57. package/src/vs/base/browser/canIUse.ts +49 -0
  58. package/src/vs/base/browser/dom.ts +2369 -0
  59. package/src/vs/base/browser/fastDomNode.ts +316 -0
  60. package/src/vs/base/browser/globalPointerMoveMonitor.ts +112 -0
  61. package/src/vs/base/browser/iframe.ts +135 -0
  62. package/src/vs/base/browser/keyboardEvent.ts +213 -0
  63. package/src/vs/base/browser/mouseEvent.ts +229 -0
  64. package/src/vs/base/browser/touch.ts +372 -0
  65. package/src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts +303 -0
  66. package/src/vs/base/browser/ui/scrollbar/horizontalScrollbar.ts +114 -0
  67. package/src/vs/base/browser/ui/scrollbar/scrollableElement.ts +720 -0
  68. package/src/vs/base/browser/ui/scrollbar/scrollableElementOptions.ts +165 -0
  69. package/src/vs/base/browser/ui/scrollbar/scrollbarArrow.ts +114 -0
  70. package/src/vs/base/browser/ui/scrollbar/scrollbarState.ts +243 -0
  71. package/src/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.ts +118 -0
  72. package/src/vs/base/browser/ui/scrollbar/verticalScrollbar.ts +116 -0
  73. package/src/vs/base/browser/ui/widget.ts +57 -0
  74. package/src/vs/base/browser/window.ts +14 -0
  75. package/src/vs/base/common/arrays.ts +887 -0
  76. package/src/vs/base/common/arraysFind.ts +202 -0
  77. package/src/vs/base/common/assert.ts +71 -0
  78. package/src/vs/base/common/async.ts +1992 -0
  79. package/src/vs/base/common/cancellation.ts +148 -0
  80. package/src/vs/base/common/charCode.ts +450 -0
  81. package/src/vs/base/common/collections.ts +140 -0
  82. package/src/vs/base/common/decorators.ts +130 -0
  83. package/src/vs/base/common/equals.ts +146 -0
  84. package/src/vs/base/common/errors.ts +303 -0
  85. package/src/vs/base/common/event.ts +1778 -0
  86. package/src/vs/base/common/functional.ts +32 -0
  87. package/src/vs/base/common/hash.ts +316 -0
  88. package/src/vs/base/common/iterator.ts +159 -0
  89. package/src/vs/base/common/keyCodes.ts +526 -0
  90. package/src/vs/base/common/keybindings.ts +284 -0
  91. package/src/vs/base/common/lazy.ts +47 -0
  92. package/src/vs/base/common/lifecycle.ts +801 -0
  93. package/src/vs/base/common/linkedList.ts +142 -0
  94. package/src/vs/base/common/map.ts +202 -0
  95. package/src/vs/base/common/numbers.ts +98 -0
  96. package/src/vs/base/common/observable.ts +76 -0
  97. package/src/vs/base/common/observableInternal/api.ts +31 -0
  98. package/src/vs/base/common/observableInternal/autorun.ts +281 -0
  99. package/src/vs/base/common/observableInternal/base.ts +489 -0
  100. package/src/vs/base/common/observableInternal/debugName.ts +145 -0
  101. package/src/vs/base/common/observableInternal/derived.ts +428 -0
  102. package/src/vs/base/common/observableInternal/lazyObservableValue.ts +146 -0
  103. package/src/vs/base/common/observableInternal/logging.ts +328 -0
  104. package/src/vs/base/common/observableInternal/promise.ts +209 -0
  105. package/src/vs/base/common/observableInternal/utils.ts +610 -0
  106. package/src/vs/base/common/platform.ts +281 -0
  107. package/src/vs/base/common/scrollable.ts +522 -0
  108. package/src/vs/base/common/sequence.ts +34 -0
  109. package/src/vs/base/common/stopwatch.ts +43 -0
  110. package/src/vs/base/common/strings.ts +557 -0
  111. package/src/vs/base/common/symbols.ts +9 -0
  112. package/src/vs/base/common/uint.ts +59 -0
  113. package/src/vs/patches/nls.ts +90 -0
  114. package/src/vs/typings/base-common.d.ts +20 -0
  115. package/src/vs/typings/require.d.ts +42 -0
  116. package/src/vs/typings/thenable.d.ts +12 -0
  117. package/src/vs/typings/vscode-globals-nls.d.ts +36 -0
  118. package/src/vs/typings/vscode-globals-product.d.ts +33 -0
  119. package/typings/xterm.d.ts +66 -15
  120. package/src/browser/Lifecycle.ts +0 -33
  121. package/src/common/EventEmitter.ts +0 -78
  122. package/src/common/Lifecycle.ts +0 -108
  123. /package/src/browser/selection/{Types.d.ts → Types.ts} +0 -0
  124. /package/src/common/parser/{Types.d.ts → Types.ts} +0 -0
@@ -0,0 +1,522 @@
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
+
6
+ import { Emitter, Event } from 'vs/base/common/event';
7
+ import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
8
+
9
+ export const enum ScrollbarVisibility {
10
+ Auto = 1,
11
+ Hidden = 2,
12
+ Visible = 3
13
+ }
14
+
15
+ export interface ScrollEvent {
16
+ inSmoothScrolling: boolean;
17
+
18
+ oldWidth: number;
19
+ oldScrollWidth: number;
20
+ oldScrollLeft: number;
21
+
22
+ width: number;
23
+ scrollWidth: number;
24
+ scrollLeft: number;
25
+
26
+ oldHeight: number;
27
+ oldScrollHeight: number;
28
+ oldScrollTop: number;
29
+
30
+ height: number;
31
+ scrollHeight: number;
32
+ scrollTop: number;
33
+
34
+ widthChanged: boolean;
35
+ scrollWidthChanged: boolean;
36
+ scrollLeftChanged: boolean;
37
+
38
+ heightChanged: boolean;
39
+ scrollHeightChanged: boolean;
40
+ scrollTopChanged: boolean;
41
+ }
42
+
43
+ export class ScrollState implements IScrollDimensions, IScrollPosition {
44
+ _scrollStateBrand: void = undefined;
45
+
46
+ public readonly rawScrollLeft: number;
47
+ public readonly rawScrollTop: number;
48
+
49
+ public readonly width: number;
50
+ public readonly scrollWidth: number;
51
+ public readonly scrollLeft: number;
52
+ public readonly height: number;
53
+ public readonly scrollHeight: number;
54
+ public readonly scrollTop: number;
55
+
56
+ constructor(
57
+ private readonly _forceIntegerValues: boolean,
58
+ width: number,
59
+ scrollWidth: number,
60
+ scrollLeft: number,
61
+ height: number,
62
+ scrollHeight: number,
63
+ scrollTop: number
64
+ ) {
65
+ if (this._forceIntegerValues) {
66
+ width = width | 0;
67
+ scrollWidth = scrollWidth | 0;
68
+ scrollLeft = scrollLeft | 0;
69
+ height = height | 0;
70
+ scrollHeight = scrollHeight | 0;
71
+ scrollTop = scrollTop | 0;
72
+ }
73
+
74
+ this.rawScrollLeft = scrollLeft; // before validation
75
+ this.rawScrollTop = scrollTop; // before validation
76
+
77
+ if (width < 0) {
78
+ width = 0;
79
+ }
80
+ if (scrollLeft + width > scrollWidth) {
81
+ scrollLeft = scrollWidth - width;
82
+ }
83
+ if (scrollLeft < 0) {
84
+ scrollLeft = 0;
85
+ }
86
+
87
+ if (height < 0) {
88
+ height = 0;
89
+ }
90
+ if (scrollTop + height > scrollHeight) {
91
+ scrollTop = scrollHeight - height;
92
+ }
93
+ if (scrollTop < 0) {
94
+ scrollTop = 0;
95
+ }
96
+
97
+ this.width = width;
98
+ this.scrollWidth = scrollWidth;
99
+ this.scrollLeft = scrollLeft;
100
+ this.height = height;
101
+ this.scrollHeight = scrollHeight;
102
+ this.scrollTop = scrollTop;
103
+ }
104
+
105
+ public equals(other: ScrollState): boolean {
106
+ return (
107
+ this.rawScrollLeft === other.rawScrollLeft
108
+ && this.rawScrollTop === other.rawScrollTop
109
+ && this.width === other.width
110
+ && this.scrollWidth === other.scrollWidth
111
+ && this.scrollLeft === other.scrollLeft
112
+ && this.height === other.height
113
+ && this.scrollHeight === other.scrollHeight
114
+ && this.scrollTop === other.scrollTop
115
+ );
116
+ }
117
+
118
+ public withScrollDimensions(update: INewScrollDimensions, useRawScrollPositions: boolean): ScrollState {
119
+ return new ScrollState(
120
+ this._forceIntegerValues,
121
+ (typeof update.width !== 'undefined' ? update.width : this.width),
122
+ (typeof update.scrollWidth !== 'undefined' ? update.scrollWidth : this.scrollWidth),
123
+ useRawScrollPositions ? this.rawScrollLeft : this.scrollLeft,
124
+ (typeof update.height !== 'undefined' ? update.height : this.height),
125
+ (typeof update.scrollHeight !== 'undefined' ? update.scrollHeight : this.scrollHeight),
126
+ useRawScrollPositions ? this.rawScrollTop : this.scrollTop
127
+ );
128
+ }
129
+
130
+ public withScrollPosition(update: INewScrollPosition): ScrollState {
131
+ return new ScrollState(
132
+ this._forceIntegerValues,
133
+ this.width,
134
+ this.scrollWidth,
135
+ (typeof update.scrollLeft !== 'undefined' ? update.scrollLeft : this.rawScrollLeft),
136
+ this.height,
137
+ this.scrollHeight,
138
+ (typeof update.scrollTop !== 'undefined' ? update.scrollTop : this.rawScrollTop)
139
+ );
140
+ }
141
+
142
+ public createScrollEvent(previous: ScrollState, inSmoothScrolling: boolean): ScrollEvent {
143
+ const widthChanged = (this.width !== previous.width);
144
+ const scrollWidthChanged = (this.scrollWidth !== previous.scrollWidth);
145
+ const scrollLeftChanged = (this.scrollLeft !== previous.scrollLeft);
146
+
147
+ const heightChanged = (this.height !== previous.height);
148
+ const scrollHeightChanged = (this.scrollHeight !== previous.scrollHeight);
149
+ const scrollTopChanged = (this.scrollTop !== previous.scrollTop);
150
+
151
+ return {
152
+ inSmoothScrolling: inSmoothScrolling,
153
+ oldWidth: previous.width,
154
+ oldScrollWidth: previous.scrollWidth,
155
+ oldScrollLeft: previous.scrollLeft,
156
+
157
+ width: this.width,
158
+ scrollWidth: this.scrollWidth,
159
+ scrollLeft: this.scrollLeft,
160
+
161
+ oldHeight: previous.height,
162
+ oldScrollHeight: previous.scrollHeight,
163
+ oldScrollTop: previous.scrollTop,
164
+
165
+ height: this.height,
166
+ scrollHeight: this.scrollHeight,
167
+ scrollTop: this.scrollTop,
168
+
169
+ widthChanged: widthChanged,
170
+ scrollWidthChanged: scrollWidthChanged,
171
+ scrollLeftChanged: scrollLeftChanged,
172
+
173
+ heightChanged: heightChanged,
174
+ scrollHeightChanged: scrollHeightChanged,
175
+ scrollTopChanged: scrollTopChanged,
176
+ };
177
+ }
178
+
179
+ }
180
+
181
+ export interface IScrollDimensions {
182
+ readonly width: number;
183
+ readonly scrollWidth: number;
184
+ readonly height: number;
185
+ readonly scrollHeight: number;
186
+ }
187
+ export interface INewScrollDimensions {
188
+ width?: number;
189
+ scrollWidth?: number;
190
+ height?: number;
191
+ scrollHeight?: number;
192
+ }
193
+
194
+ export interface IScrollPosition {
195
+ readonly scrollLeft: number;
196
+ readonly scrollTop: number;
197
+ }
198
+ export interface ISmoothScrollPosition {
199
+ readonly scrollLeft: number;
200
+ readonly scrollTop: number;
201
+
202
+ readonly width: number;
203
+ readonly height: number;
204
+ }
205
+ export interface INewScrollPosition {
206
+ scrollLeft?: number;
207
+ scrollTop?: number;
208
+ }
209
+
210
+ export interface IScrollableOptions {
211
+ /**
212
+ * Define if the scroll values should always be integers.
213
+ */
214
+ forceIntegerValues: boolean;
215
+ /**
216
+ * Set the duration (ms) used for smooth scroll animations.
217
+ */
218
+ smoothScrollDuration: number;
219
+ /**
220
+ * A function to schedule an update at the next frame (used for smooth scroll animations).
221
+ */
222
+ scheduleAtNextAnimationFrame: (callback: () => void) => IDisposable;
223
+ }
224
+
225
+ export class Scrollable extends Disposable {
226
+
227
+ _scrollableBrand: void = undefined;
228
+
229
+ private _smoothScrollDuration: number;
230
+ private readonly _scheduleAtNextAnimationFrame: (callback: () => void) => IDisposable;
231
+ private _state: ScrollState;
232
+ private _smoothScrolling: SmoothScrollingOperation | null;
233
+
234
+ private _onScroll = this._register(new Emitter<ScrollEvent>());
235
+ public readonly onScroll: Event<ScrollEvent> = this._onScroll.event;
236
+
237
+ constructor(options: IScrollableOptions) {
238
+ super();
239
+
240
+ this._smoothScrollDuration = options.smoothScrollDuration;
241
+ this._scheduleAtNextAnimationFrame = options.scheduleAtNextAnimationFrame;
242
+ this._state = new ScrollState(options.forceIntegerValues, 0, 0, 0, 0, 0, 0);
243
+ this._smoothScrolling = null;
244
+ }
245
+
246
+ public override dispose(): void {
247
+ if (this._smoothScrolling) {
248
+ this._smoothScrolling.dispose();
249
+ this._smoothScrolling = null;
250
+ }
251
+ super.dispose();
252
+ }
253
+
254
+ public setSmoothScrollDuration(smoothScrollDuration: number): void {
255
+ this._smoothScrollDuration = smoothScrollDuration;
256
+ }
257
+
258
+ public validateScrollPosition(scrollPosition: INewScrollPosition): IScrollPosition {
259
+ return this._state.withScrollPosition(scrollPosition);
260
+ }
261
+
262
+ public getScrollDimensions(): IScrollDimensions {
263
+ return this._state;
264
+ }
265
+
266
+ public setScrollDimensions(dimensions: INewScrollDimensions, useRawScrollPositions: boolean): void {
267
+ const newState = this._state.withScrollDimensions(dimensions, useRawScrollPositions);
268
+ this._setState(newState, Boolean(this._smoothScrolling));
269
+
270
+ // Validate outstanding animated scroll position target
271
+ this._smoothScrolling?.acceptScrollDimensions(this._state);
272
+ }
273
+
274
+ /**
275
+ * Returns the final scroll position that the instance will have once the smooth scroll animation concludes.
276
+ * If no scroll animation is occurring, it will return the current scroll position instead.
277
+ */
278
+ public getFutureScrollPosition(): IScrollPosition {
279
+ if (this._smoothScrolling) {
280
+ return this._smoothScrolling.to;
281
+ }
282
+ return this._state;
283
+ }
284
+
285
+ /**
286
+ * Returns the current scroll position.
287
+ * Note: This result might be an intermediate scroll position, as there might be an ongoing smooth scroll animation.
288
+ */
289
+ public getCurrentScrollPosition(): IScrollPosition {
290
+ return this._state;
291
+ }
292
+
293
+ public setScrollPositionNow(update: INewScrollPosition): void {
294
+ // no smooth scrolling requested
295
+ const newState = this._state.withScrollPosition(update);
296
+
297
+ // Terminate any outstanding smooth scrolling
298
+ if (this._smoothScrolling) {
299
+ this._smoothScrolling.dispose();
300
+ this._smoothScrolling = null;
301
+ }
302
+
303
+ this._setState(newState, false);
304
+ }
305
+
306
+ public setScrollPositionSmooth(update: INewScrollPosition, reuseAnimation?: boolean): void {
307
+ if (this._smoothScrollDuration === 0) {
308
+ // Smooth scrolling not supported.
309
+ return this.setScrollPositionNow(update);
310
+ }
311
+
312
+ if (this._smoothScrolling) {
313
+ // Combine our pending scrollLeft/scrollTop with incoming scrollLeft/scrollTop
314
+ update = {
315
+ scrollLeft: (typeof update.scrollLeft === 'undefined' ? this._smoothScrolling.to.scrollLeft : update.scrollLeft),
316
+ scrollTop: (typeof update.scrollTop === 'undefined' ? this._smoothScrolling.to.scrollTop : update.scrollTop)
317
+ };
318
+
319
+ // Validate `update`
320
+ const validTarget = this._state.withScrollPosition(update);
321
+
322
+ if (this._smoothScrolling.to.scrollLeft === validTarget.scrollLeft && this._smoothScrolling.to.scrollTop === validTarget.scrollTop) {
323
+ // No need to interrupt or extend the current animation since we're going to the same place
324
+ return;
325
+ }
326
+ let newSmoothScrolling: SmoothScrollingOperation;
327
+ if (reuseAnimation) {
328
+ newSmoothScrolling = new SmoothScrollingOperation(this._smoothScrolling.from, validTarget, this._smoothScrolling.startTime, this._smoothScrolling.duration);
329
+ } else {
330
+ newSmoothScrolling = this._smoothScrolling.combine(this._state, validTarget, this._smoothScrollDuration);
331
+ }
332
+ this._smoothScrolling.dispose();
333
+ this._smoothScrolling = newSmoothScrolling;
334
+ } else {
335
+ // Validate `update`
336
+ const validTarget = this._state.withScrollPosition(update);
337
+
338
+ this._smoothScrolling = SmoothScrollingOperation.start(this._state, validTarget, this._smoothScrollDuration);
339
+ }
340
+
341
+ // Begin smooth scrolling animation
342
+ this._smoothScrolling.animationFrameDisposable = this._scheduleAtNextAnimationFrame(() => {
343
+ if (!this._smoothScrolling) {
344
+ return;
345
+ }
346
+ this._smoothScrolling.animationFrameDisposable = null;
347
+ this._performSmoothScrolling();
348
+ });
349
+ }
350
+
351
+ public hasPendingScrollAnimation(): boolean {
352
+ return Boolean(this._smoothScrolling);
353
+ }
354
+
355
+ private _performSmoothScrolling(): void {
356
+ if (!this._smoothScrolling) {
357
+ return;
358
+ }
359
+ const update = this._smoothScrolling.tick();
360
+ const newState = this._state.withScrollPosition(update);
361
+
362
+ this._setState(newState, true);
363
+
364
+ if (!this._smoothScrolling) {
365
+ // Looks like someone canceled the smooth scrolling
366
+ // from the scroll event handler
367
+ return;
368
+ }
369
+
370
+ if (update.isDone) {
371
+ this._smoothScrolling.dispose();
372
+ this._smoothScrolling = null;
373
+ return;
374
+ }
375
+
376
+ // Continue smooth scrolling animation
377
+ this._smoothScrolling.animationFrameDisposable = this._scheduleAtNextAnimationFrame(() => {
378
+ if (!this._smoothScrolling) {
379
+ return;
380
+ }
381
+ this._smoothScrolling.animationFrameDisposable = null;
382
+ this._performSmoothScrolling();
383
+ });
384
+ }
385
+
386
+ private _setState(newState: ScrollState, inSmoothScrolling: boolean): void {
387
+ const oldState = this._state;
388
+ if (oldState.equals(newState)) {
389
+ // no change
390
+ return;
391
+ }
392
+ this._state = newState;
393
+ this._onScroll.fire(this._state.createScrollEvent(oldState, inSmoothScrolling));
394
+ }
395
+ }
396
+
397
+ export class SmoothScrollingUpdate {
398
+
399
+ public readonly scrollLeft: number;
400
+ public readonly scrollTop: number;
401
+ public readonly isDone: boolean;
402
+
403
+ constructor(scrollLeft: number, scrollTop: number, isDone: boolean) {
404
+ this.scrollLeft = scrollLeft;
405
+ this.scrollTop = scrollTop;
406
+ this.isDone = isDone;
407
+ }
408
+
409
+ }
410
+
411
+ interface IAnimation {
412
+ (completion: number): number;
413
+ }
414
+
415
+ function createEaseOutCubic(from: number, to: number): IAnimation {
416
+ const delta = to - from;
417
+ return function (completion: number): number {
418
+ return from + delta * easeOutCubic(completion);
419
+ };
420
+ }
421
+
422
+ function createComposed(a: IAnimation, b: IAnimation, cut: number): IAnimation {
423
+ return function (completion: number): number {
424
+ if (completion < cut) {
425
+ return a(completion / cut);
426
+ }
427
+ return b((completion - cut) / (1 - cut));
428
+ };
429
+ }
430
+
431
+ export class SmoothScrollingOperation {
432
+
433
+ public readonly from: ISmoothScrollPosition;
434
+ public to: ISmoothScrollPosition;
435
+ public readonly duration: number;
436
+ public readonly startTime: number;
437
+ public animationFrameDisposable: IDisposable | null;
438
+
439
+ private scrollLeft!: IAnimation;
440
+ private scrollTop!: IAnimation;
441
+
442
+ constructor(from: ISmoothScrollPosition, to: ISmoothScrollPosition, startTime: number, duration: number) {
443
+ this.from = from;
444
+ this.to = to;
445
+ this.duration = duration;
446
+ this.startTime = startTime;
447
+
448
+ this.animationFrameDisposable = null;
449
+
450
+ this._initAnimations();
451
+ }
452
+
453
+ private _initAnimations(): void {
454
+ this.scrollLeft = this._initAnimation(this.from.scrollLeft, this.to.scrollLeft, this.to.width);
455
+ this.scrollTop = this._initAnimation(this.from.scrollTop, this.to.scrollTop, this.to.height);
456
+ }
457
+
458
+ private _initAnimation(from: number, to: number, viewportSize: number): IAnimation {
459
+ const delta = Math.abs(from - to);
460
+ if (delta > 2.5 * viewportSize) {
461
+ let stop1: number, stop2: number;
462
+ if (from < to) {
463
+ // scroll to 75% of the viewportSize
464
+ stop1 = from + 0.75 * viewportSize;
465
+ stop2 = to - 0.75 * viewportSize;
466
+ } else {
467
+ stop1 = from - 0.75 * viewportSize;
468
+ stop2 = to + 0.75 * viewportSize;
469
+ }
470
+ return createComposed(createEaseOutCubic(from, stop1), createEaseOutCubic(stop2, to), 0.33);
471
+ }
472
+ return createEaseOutCubic(from, to);
473
+ }
474
+
475
+ public dispose(): void {
476
+ if (this.animationFrameDisposable !== null) {
477
+ this.animationFrameDisposable.dispose();
478
+ this.animationFrameDisposable = null;
479
+ }
480
+ }
481
+
482
+ public acceptScrollDimensions(state: ScrollState): void {
483
+ this.to = state.withScrollPosition(this.to);
484
+ this._initAnimations();
485
+ }
486
+
487
+ public tick(): SmoothScrollingUpdate {
488
+ return this._tick(Date.now());
489
+ }
490
+
491
+ protected _tick(now: number): SmoothScrollingUpdate {
492
+ const completion = (now - this.startTime) / this.duration;
493
+
494
+ if (completion < 1) {
495
+ const newScrollLeft = this.scrollLeft(completion);
496
+ const newScrollTop = this.scrollTop(completion);
497
+ return new SmoothScrollingUpdate(newScrollLeft, newScrollTop, false);
498
+ }
499
+
500
+ return new SmoothScrollingUpdate(this.to.scrollLeft, this.to.scrollTop, true);
501
+ }
502
+
503
+ public combine(from: ISmoothScrollPosition, to: ISmoothScrollPosition, duration: number): SmoothScrollingOperation {
504
+ return SmoothScrollingOperation.start(from, to, duration);
505
+ }
506
+
507
+ public static start(from: ISmoothScrollPosition, to: ISmoothScrollPosition, duration: number): SmoothScrollingOperation {
508
+ // +10 / -10 : pretend the animation already started for a quicker response to a scroll request
509
+ duration = duration + 10;
510
+ const startTime = Date.now() - 10;
511
+
512
+ return new SmoothScrollingOperation(from, to, startTime, duration);
513
+ }
514
+ }
515
+
516
+ function easeInCubic(t: number) {
517
+ return Math.pow(t, 3);
518
+ }
519
+
520
+ function easeOutCubic(t: number) {
521
+ return 1 - easeInCubic(1 - t);
522
+ }
@@ -0,0 +1,34 @@
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
+
6
+ import { Emitter, Event } from 'vs/base/common/event';
7
+
8
+ export interface ISplice<T> {
9
+ readonly start: number;
10
+ readonly deleteCount: number;
11
+ readonly toInsert: readonly T[];
12
+ }
13
+
14
+ export interface ISpliceable<T> {
15
+ splice(start: number, deleteCount: number, toInsert: readonly T[]): void;
16
+ }
17
+
18
+ export interface ISequence<T> {
19
+ readonly elements: T[];
20
+ readonly onDidSplice: Event<ISplice<T>>;
21
+ }
22
+
23
+ export class Sequence<T> implements ISequence<T>, ISpliceable<T> {
24
+
25
+ readonly elements: T[] = [];
26
+
27
+ private readonly _onDidSplice = new Emitter<ISplice<T>>();
28
+ readonly onDidSplice: Event<ISplice<T>> = this._onDidSplice.event;
29
+
30
+ splice(start: number, deleteCount: number, toInsert: readonly T[] = []): void {
31
+ this.elements.splice(start, deleteCount, ...toInsert);
32
+ this._onDidSplice.fire({ start, deleteCount, toInsert });
33
+ }
34
+ }
@@ -0,0 +1,43 @@
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
+
6
+ // fake definition so that the valid layers check won't trip on this
7
+ declare const globalThis: { performance?: { now(): number } };
8
+
9
+ const hasPerformanceNow = (globalThis.performance && typeof globalThis.performance.now === 'function');
10
+
11
+ export class StopWatch {
12
+
13
+ private _startTime: number;
14
+ private _stopTime: number;
15
+
16
+ private readonly _now: () => number;
17
+
18
+ public static create(highResolution?: boolean): StopWatch {
19
+ return new StopWatch(highResolution);
20
+ }
21
+
22
+ constructor(highResolution?: boolean) {
23
+ this._now = hasPerformanceNow && highResolution === false ? Date.now : globalThis.performance!.now.bind(globalThis.performance);
24
+ this._startTime = this._now();
25
+ this._stopTime = -1;
26
+ }
27
+
28
+ public stop(): void {
29
+ this._stopTime = this._now();
30
+ }
31
+
32
+ public reset(): void {
33
+ this._startTime = this._now();
34
+ this._stopTime = -1;
35
+ }
36
+
37
+ public elapsed(): number {
38
+ if (this._stopTime !== -1) {
39
+ return this._stopTime - this._startTime;
40
+ }
41
+ return this._now() - this._startTime;
42
+ }
43
+ }