@xterm/xterm 6.1.0-beta.24 → 6.1.0-beta.240

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 (162) hide show
  1. package/README.md +62 -38
  2. package/css/xterm.css +29 -22
  3. package/lib/xterm.js +1 -1
  4. package/lib/xterm.js.map +1 -1
  5. package/lib/xterm.mjs +8 -34
  6. package/lib/xterm.mjs.map +4 -4
  7. package/package.json +25 -22
  8. package/src/browser/AccessibilityManager.ts +11 -6
  9. package/src/browser/Clipboard.ts +6 -3
  10. package/src/browser/CoreBrowserTerminal.ts +149 -319
  11. package/src/browser/Dom.ts +178 -0
  12. package/src/browser/Linkifier.ts +11 -11
  13. package/src/browser/OscLinkProvider.ts +82 -14
  14. package/src/browser/RenderDebouncer.ts +2 -2
  15. package/src/browser/TimeBasedDebouncer.ts +2 -2
  16. package/src/browser/Types.ts +12 -11
  17. package/src/browser/Viewport.ts +55 -20
  18. package/src/browser/decorations/BufferDecorationRenderer.ts +1 -1
  19. package/src/browser/decorations/OverviewRulerRenderer.ts +33 -17
  20. package/src/browser/input/CompositionHelper.ts +44 -8
  21. package/src/browser/public/Terminal.ts +25 -28
  22. package/src/browser/renderer/dom/DomRenderer.ts +242 -76
  23. package/src/browser/renderer/dom/DomRendererRowFactory.ts +19 -13
  24. package/src/browser/renderer/dom/WidthCache.ts +54 -52
  25. package/src/browser/renderer/shared/Constants.ts +7 -0
  26. package/src/browser/renderer/shared/TextBlinkStateManager.ts +97 -0
  27. package/src/browser/renderer/shared/Types.ts +8 -2
  28. package/src/browser/scrollable/abstractScrollbar.ts +300 -0
  29. package/src/browser/scrollable/fastDomNode.ts +126 -0
  30. package/src/browser/scrollable/globalPointerMoveMonitor.ts +90 -0
  31. package/src/browser/scrollable/horizontalScrollbar.ts +85 -0
  32. package/src/browser/scrollable/mouseEvent.ts +292 -0
  33. package/src/browser/scrollable/scrollable.ts +486 -0
  34. package/src/browser/scrollable/scrollableElement.ts +581 -0
  35. package/src/browser/scrollable/scrollableElementOptions.ts +161 -0
  36. package/src/browser/scrollable/scrollbarArrow.ts +110 -0
  37. package/src/browser/scrollable/scrollbarState.ts +246 -0
  38. package/src/browser/scrollable/scrollbarVisibilityController.ts +113 -0
  39. package/src/browser/scrollable/touch.ts +485 -0
  40. package/src/browser/scrollable/verticalScrollbar.ts +143 -0
  41. package/src/browser/scrollable/widget.ts +23 -0
  42. package/src/browser/services/CharSizeService.ts +2 -2
  43. package/src/browser/services/CoreBrowserService.ts +7 -5
  44. package/src/browser/services/KeyboardService.ts +67 -0
  45. package/src/browser/services/LinkProviderService.ts +1 -1
  46. package/src/browser/services/MouseCoordsService.ts +47 -0
  47. package/src/browser/services/MouseService.ts +518 -25
  48. package/src/browser/services/RenderService.ts +28 -16
  49. package/src/browser/services/SelectionService.ts +45 -39
  50. package/src/browser/services/Services.ts +40 -17
  51. package/src/browser/services/ThemeService.ts +2 -2
  52. package/src/common/Async.ts +141 -0
  53. package/src/common/CircularList.ts +2 -2
  54. package/src/common/Color.ts +8 -0
  55. package/src/common/CoreTerminal.ts +31 -21
  56. package/src/common/Event.ts +118 -0
  57. package/src/common/InputHandler.ts +283 -85
  58. package/src/common/Lifecycle.ts +113 -0
  59. package/src/common/Platform.ts +13 -3
  60. package/src/common/SortedList.ts +7 -3
  61. package/src/common/StringBuilder.ts +67 -0
  62. package/src/common/TaskQueue.ts +14 -5
  63. package/src/common/Types.ts +51 -31
  64. package/src/common/Version.ts +9 -0
  65. package/src/common/buffer/Buffer.ts +34 -19
  66. package/src/common/buffer/BufferLine.ts +133 -65
  67. package/src/common/buffer/BufferLineStringCache.ts +69 -0
  68. package/src/common/buffer/BufferSet.ts +11 -6
  69. package/src/common/buffer/CellData.ts +57 -0
  70. package/src/common/buffer/Marker.ts +2 -2
  71. package/src/common/buffer/Types.ts +6 -2
  72. package/src/common/data/EscapeSequences.ts +71 -70
  73. package/src/common/input/Keyboard.ts +14 -7
  74. package/src/common/input/KittyKeyboard.ts +526 -0
  75. package/src/common/input/Win32InputMode.ts +297 -0
  76. package/src/common/input/WriteBuffer.ts +69 -32
  77. package/src/common/input/XParseColor.ts +2 -2
  78. package/src/common/parser/ApcParser.ts +196 -0
  79. package/src/common/parser/Constants.ts +14 -4
  80. package/src/common/parser/DcsParser.ts +11 -12
  81. package/src/common/parser/EscapeSequenceParser.ts +205 -63
  82. package/src/common/parser/OscParser.ts +11 -12
  83. package/src/common/parser/Params.ts +27 -8
  84. package/src/common/parser/Types.ts +36 -2
  85. package/src/common/public/BufferLineApiView.ts +2 -2
  86. package/src/common/public/BufferNamespaceApi.ts +3 -3
  87. package/src/common/public/ParserApi.ts +3 -0
  88. package/src/common/services/BufferService.ts +14 -9
  89. package/src/common/services/CharsetService.ts +4 -0
  90. package/src/common/services/CoreService.ts +22 -9
  91. package/src/common/services/DecorationService.ts +258 -8
  92. package/src/common/services/LogService.ts +1 -31
  93. package/src/common/services/{CoreMouseService.ts → MouseStateService.ts} +21 -132
  94. package/src/common/services/OptionsService.ts +13 -4
  95. package/src/common/services/ServiceRegistry.ts +9 -7
  96. package/src/common/services/Services.ts +49 -40
  97. package/src/common/services/UnicodeService.ts +1 -1
  98. package/typings/xterm.d.ts +318 -34
  99. package/src/common/Clone.ts +0 -23
  100. package/src/common/TypedArrayUtils.ts +0 -17
  101. package/src/vs/base/browser/browser.ts +0 -141
  102. package/src/vs/base/browser/canIUse.ts +0 -49
  103. package/src/vs/base/browser/dom.ts +0 -2369
  104. package/src/vs/base/browser/fastDomNode.ts +0 -316
  105. package/src/vs/base/browser/globalPointerMoveMonitor.ts +0 -112
  106. package/src/vs/base/browser/iframe.ts +0 -135
  107. package/src/vs/base/browser/keyboardEvent.ts +0 -213
  108. package/src/vs/base/browser/mouseEvent.ts +0 -229
  109. package/src/vs/base/browser/touch.ts +0 -372
  110. package/src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts +0 -303
  111. package/src/vs/base/browser/ui/scrollbar/horizontalScrollbar.ts +0 -114
  112. package/src/vs/base/browser/ui/scrollbar/scrollableElement.ts +0 -720
  113. package/src/vs/base/browser/ui/scrollbar/scrollableElementOptions.ts +0 -165
  114. package/src/vs/base/browser/ui/scrollbar/scrollbarArrow.ts +0 -114
  115. package/src/vs/base/browser/ui/scrollbar/scrollbarState.ts +0 -243
  116. package/src/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.ts +0 -118
  117. package/src/vs/base/browser/ui/scrollbar/verticalScrollbar.ts +0 -116
  118. package/src/vs/base/browser/ui/widget.ts +0 -57
  119. package/src/vs/base/browser/window.ts +0 -14
  120. package/src/vs/base/common/arrays.ts +0 -887
  121. package/src/vs/base/common/arraysFind.ts +0 -202
  122. package/src/vs/base/common/assert.ts +0 -71
  123. package/src/vs/base/common/async.ts +0 -1992
  124. package/src/vs/base/common/cancellation.ts +0 -148
  125. package/src/vs/base/common/charCode.ts +0 -450
  126. package/src/vs/base/common/collections.ts +0 -140
  127. package/src/vs/base/common/decorators.ts +0 -130
  128. package/src/vs/base/common/equals.ts +0 -146
  129. package/src/vs/base/common/errors.ts +0 -303
  130. package/src/vs/base/common/event.ts +0 -1778
  131. package/src/vs/base/common/functional.ts +0 -32
  132. package/src/vs/base/common/hash.ts +0 -316
  133. package/src/vs/base/common/iterator.ts +0 -159
  134. package/src/vs/base/common/keyCodes.ts +0 -526
  135. package/src/vs/base/common/keybindings.ts +0 -284
  136. package/src/vs/base/common/lazy.ts +0 -47
  137. package/src/vs/base/common/lifecycle.ts +0 -801
  138. package/src/vs/base/common/linkedList.ts +0 -142
  139. package/src/vs/base/common/map.ts +0 -202
  140. package/src/vs/base/common/numbers.ts +0 -98
  141. package/src/vs/base/common/observable.ts +0 -76
  142. package/src/vs/base/common/observableInternal/api.ts +0 -31
  143. package/src/vs/base/common/observableInternal/autorun.ts +0 -281
  144. package/src/vs/base/common/observableInternal/base.ts +0 -489
  145. package/src/vs/base/common/observableInternal/debugName.ts +0 -145
  146. package/src/vs/base/common/observableInternal/derived.ts +0 -428
  147. package/src/vs/base/common/observableInternal/lazyObservableValue.ts +0 -146
  148. package/src/vs/base/common/observableInternal/logging.ts +0 -328
  149. package/src/vs/base/common/observableInternal/promise.ts +0 -209
  150. package/src/vs/base/common/observableInternal/utils.ts +0 -610
  151. package/src/vs/base/common/platform.ts +0 -281
  152. package/src/vs/base/common/scrollable.ts +0 -522
  153. package/src/vs/base/common/sequence.ts +0 -34
  154. package/src/vs/base/common/stopwatch.ts +0 -43
  155. package/src/vs/base/common/strings.ts +0 -557
  156. package/src/vs/base/common/symbols.ts +0 -9
  157. package/src/vs/base/common/uint.ts +0 -59
  158. package/src/vs/patches/nls.ts +0 -90
  159. package/src/vs/typings/base-common.d.ts +0 -20
  160. package/src/vs/typings/require.d.ts +0 -42
  161. package/src/vs/typings/vscode-globals-nls.d.ts +0 -36
  162. package/src/vs/typings/vscode-globals-product.d.ts +0 -33
@@ -1,522 +0,0 @@
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
- }
@@ -1,34 +0,0 @@
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
- }
@@ -1,43 +0,0 @@
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
- }