@xterm/xterm 5.6.0-beta.5 → 5.6.0-beta.51

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 (118) hide show
  1. package/README.md +6 -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 +40 -31
  8. package/src/browser/AccessibilityManager.ts +53 -25
  9. package/src/browser/{Terminal.ts → CoreBrowserTerminal.ts} +132 -144
  10. package/src/browser/Linkifier.ts +15 -13
  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 +142 -364
  14. package/src/browser/decorations/BufferDecorationRenderer.ts +14 -9
  15. package/src/browser/decorations/OverviewRulerRenderer.ts +40 -44
  16. package/src/browser/public/Terminal.ts +25 -19
  17. package/src/browser/renderer/dom/DomRenderer.ts +14 -16
  18. package/src/browser/renderer/shared/CharAtlasUtils.ts +4 -0
  19. package/src/browser/renderer/shared/CustomGlyphs.ts +6 -0
  20. package/src/browser/renderer/shared/DevicePixelObserver.ts +1 -2
  21. package/src/browser/renderer/shared/TextureAtlas.ts +3 -3
  22. package/src/browser/renderer/shared/{Types.d.ts → Types.ts} +4 -4
  23. package/src/browser/services/CharSizeService.ts +6 -6
  24. package/src/browser/services/CoreBrowserService.ts +15 -15
  25. package/src/browser/services/LinkProviderService.ts +2 -2
  26. package/src/browser/services/RenderService.ts +20 -20
  27. package/src/browser/services/SelectionService.ts +8 -8
  28. package/src/browser/services/Services.ts +13 -13
  29. package/src/browser/services/ThemeService.ts +17 -56
  30. package/src/browser/shared/Constants.ts +8 -0
  31. package/src/common/CircularList.ts +5 -5
  32. package/src/common/CoreTerminal.ts +35 -41
  33. package/src/common/InputHandler.ts +34 -28
  34. package/src/common/{Types.d.ts → Types.ts} +11 -17
  35. package/src/common/buffer/Buffer.ts +5 -1
  36. package/src/common/buffer/BufferSet.ts +5 -5
  37. package/src/common/buffer/Marker.ts +4 -4
  38. package/src/common/buffer/{Types.d.ts → Types.ts} +2 -2
  39. package/src/common/input/WriteBuffer.ts +3 -3
  40. package/src/common/parser/EscapeSequenceParser.ts +4 -4
  41. package/src/common/public/BufferNamespaceApi.ts +3 -3
  42. package/src/common/services/BufferService.ts +7 -7
  43. package/src/common/services/CoreMouseService.ts +5 -3
  44. package/src/common/services/CoreService.ts +6 -6
  45. package/src/common/services/DecorationService.ts +8 -9
  46. package/src/common/services/LogService.ts +2 -2
  47. package/src/common/services/OptionsService.ts +5 -5
  48. package/src/common/services/Services.ts +24 -17
  49. package/src/common/services/UnicodeService.ts +2 -2
  50. package/src/vs/base/browser/browser.ts +141 -0
  51. package/src/vs/base/browser/canIUse.ts +49 -0
  52. package/src/vs/base/browser/dom.ts +2369 -0
  53. package/src/vs/base/browser/fastDomNode.ts +316 -0
  54. package/src/vs/base/browser/globalPointerMoveMonitor.ts +112 -0
  55. package/src/vs/base/browser/iframe.ts +135 -0
  56. package/src/vs/base/browser/keyboardEvent.ts +213 -0
  57. package/src/vs/base/browser/mouseEvent.ts +229 -0
  58. package/src/vs/base/browser/touch.ts +372 -0
  59. package/src/vs/base/browser/ui/scrollbar/abstractScrollbar.ts +303 -0
  60. package/src/vs/base/browser/ui/scrollbar/horizontalScrollbar.ts +114 -0
  61. package/src/vs/base/browser/ui/scrollbar/scrollableElement.ts +720 -0
  62. package/src/vs/base/browser/ui/scrollbar/scrollableElementOptions.ts +165 -0
  63. package/src/vs/base/browser/ui/scrollbar/scrollbarArrow.ts +114 -0
  64. package/src/vs/base/browser/ui/scrollbar/scrollbarState.ts +243 -0
  65. package/src/vs/base/browser/ui/scrollbar/scrollbarVisibilityController.ts +118 -0
  66. package/src/vs/base/browser/ui/scrollbar/verticalScrollbar.ts +116 -0
  67. package/src/vs/base/browser/ui/widget.ts +57 -0
  68. package/src/vs/base/browser/window.ts +14 -0
  69. package/src/vs/base/common/arrays.ts +887 -0
  70. package/src/vs/base/common/arraysFind.ts +202 -0
  71. package/src/vs/base/common/assert.ts +71 -0
  72. package/src/vs/base/common/async.ts +1992 -0
  73. package/src/vs/base/common/cancellation.ts +148 -0
  74. package/src/vs/base/common/charCode.ts +450 -0
  75. package/src/vs/base/common/collections.ts +140 -0
  76. package/src/vs/base/common/decorators.ts +130 -0
  77. package/src/vs/base/common/equals.ts +146 -0
  78. package/src/vs/base/common/errors.ts +303 -0
  79. package/src/vs/base/common/event.ts +1778 -0
  80. package/src/vs/base/common/functional.ts +32 -0
  81. package/src/vs/base/common/hash.ts +316 -0
  82. package/src/vs/base/common/iterator.ts +159 -0
  83. package/src/vs/base/common/keyCodes.ts +526 -0
  84. package/src/vs/base/common/keybindings.ts +284 -0
  85. package/src/vs/base/common/lazy.ts +47 -0
  86. package/src/vs/base/common/lifecycle.ts +801 -0
  87. package/src/vs/base/common/linkedList.ts +142 -0
  88. package/src/vs/base/common/map.ts +202 -0
  89. package/src/vs/base/common/numbers.ts +98 -0
  90. package/src/vs/base/common/observable.ts +76 -0
  91. package/src/vs/base/common/observableInternal/api.ts +31 -0
  92. package/src/vs/base/common/observableInternal/autorun.ts +281 -0
  93. package/src/vs/base/common/observableInternal/base.ts +489 -0
  94. package/src/vs/base/common/observableInternal/debugName.ts +145 -0
  95. package/src/vs/base/common/observableInternal/derived.ts +428 -0
  96. package/src/vs/base/common/observableInternal/lazyObservableValue.ts +146 -0
  97. package/src/vs/base/common/observableInternal/logging.ts +328 -0
  98. package/src/vs/base/common/observableInternal/promise.ts +209 -0
  99. package/src/vs/base/common/observableInternal/utils.ts +610 -0
  100. package/src/vs/base/common/platform.ts +281 -0
  101. package/src/vs/base/common/scrollable.ts +522 -0
  102. package/src/vs/base/common/sequence.ts +34 -0
  103. package/src/vs/base/common/stopwatch.ts +43 -0
  104. package/src/vs/base/common/strings.ts +557 -0
  105. package/src/vs/base/common/symbols.ts +9 -0
  106. package/src/vs/base/common/uint.ts +59 -0
  107. package/src/vs/patches/nls.ts +90 -0
  108. package/src/vs/typings/base-common.d.ts +20 -0
  109. package/src/vs/typings/require.d.ts +42 -0
  110. package/src/vs/typings/thenable.d.ts +12 -0
  111. package/src/vs/typings/vscode-globals-nls.d.ts +36 -0
  112. package/src/vs/typings/vscode-globals-product.d.ts +33 -0
  113. package/typings/xterm.d.ts +59 -15
  114. package/src/browser/Lifecycle.ts +0 -33
  115. package/src/common/EventEmitter.ts +0 -78
  116. package/src/common/Lifecycle.ts +0 -108
  117. /package/src/browser/selection/{Types.d.ts → Types.ts} +0 -0
  118. /package/src/common/parser/{Types.d.ts → Types.ts} +0 -0
@@ -1,408 +1,186 @@
1
1
  /**
2
- * Copyright (c) 2016 The xterm.js authors. All rights reserved.
2
+ * Copyright (c) 2024 The xterm.js authors. All rights reserved.
3
3
  * @license MIT
4
4
  */
5
5
 
6
- import { addDisposableDomListener } from 'browser/Lifecycle';
7
- import { IViewport, ReadonlyColorSet } from 'browser/Types';
8
- import { IRenderDimensions } from 'browser/renderer/shared/Types';
9
- import { ICharSizeService, ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
10
- import { EventEmitter } from 'common/EventEmitter';
11
- import { Disposable } from 'common/Lifecycle';
12
- import { IBuffer } from 'common/buffer/Types';
13
- import { IBufferService, IOptionsService } from 'common/services/Services';
6
+ import { ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services';
7
+ import { ViewportConstants } from 'browser/shared/Constants';
8
+ import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
9
+ import { IBufferService, ICoreMouseService, IOptionsService } from 'common/services/Services';
10
+ import { CoreMouseEventType } from 'common/Types';
11
+ import { scheduleAtNextAnimationFrame } from 'vs/base/browser/dom';
12
+ import { SmoothScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
13
+ import type { ScrollableElementChangeOptions } from 'vs/base/browser/ui/scrollbar/scrollableElementOptions';
14
+ import { Emitter, Event } from 'vs/base/common/event';
15
+ import { Scrollable, ScrollbarVisibility, type ScrollEvent } from 'vs/base/common/scrollable';
14
16
 
15
- const FALLBACK_SCROLL_BAR_WIDTH = 15;
17
+ export class Viewport extends Disposable {
16
18
 
17
- interface ISmoothScrollState {
18
- startTime: number;
19
- origin: number;
20
- target: number;
21
- }
22
-
23
- /**
24
- * Represents the viewport of a terminal, the visible area within the larger buffer of output.
25
- * Logic for the virtual scroll bar is included in this object.
26
- */
27
- export class Viewport extends Disposable implements IViewport {
28
- public scrollBarWidth: number = 0;
29
- private _currentRowHeight: number = 0;
30
- private _currentDeviceCellHeight: number = 0;
31
- private _lastRecordedBufferLength: number = 0;
32
- private _lastRecordedViewportHeight: number = 0;
33
- private _lastRecordedBufferHeight: number = 0;
34
- private _lastTouchY: number = 0;
35
- private _lastScrollTop: number = 0;
36
- private _activeBuffer: IBuffer;
37
- private _renderDimensions: IRenderDimensions;
38
-
39
- private _smoothScrollAnimationFrame: number = 0;
40
-
41
- // Stores a partial line amount when scrolling, this is used to keep track of how much of a line
42
- // is scrolled so we can "scroll" over partial lines and feel natural on touchpads. This is a
43
- // quick fix and could have a more robust solution in place that reset the value when needed.
44
- private _wheelPartialScroll: number = 0;
19
+ protected _onRequestScrollLines = this._register(new Emitter<number>());
20
+ public readonly onRequestScrollLines = this._onRequestScrollLines.event;
45
21
 
46
- private _refreshAnimationFrame: number | null = null;
47
- private _ignoreNextScrollEvent: boolean = false;
48
- private _smoothScrollState: ISmoothScrollState = {
49
- startTime: 0,
50
- origin: -1,
51
- target: -1
52
- };
22
+ private _scrollableElement: SmoothScrollableElement;
23
+ private _styleElement: HTMLStyleElement;
53
24
 
54
- private readonly _onRequestScrollLines = this.register(new EventEmitter<{ amount: number, suppressScrollEvent: boolean }>());
55
- public readonly onRequestScrollLines = this._onRequestScrollLines.event;
25
+ private _queuedAnimationFrame?: number;
26
+ private _latestYDisp?: number;
27
+ private _isSyncing: boolean = false;
28
+ private _isHandlingScroll: boolean = false;
29
+ private _suppressOnScrollHandler: boolean = false;
56
30
 
57
31
  constructor(
58
- private readonly _viewportElement: HTMLElement,
59
- private readonly _scrollArea: HTMLElement,
32
+ element: HTMLElement,
33
+ screenElement: HTMLElement,
60
34
  @IBufferService private readonly _bufferService: IBufferService,
35
+ @ICoreBrowserService coreBrowserService: ICoreBrowserService,
36
+ @ICoreMouseService coreMouseService: ICoreMouseService,
37
+ @IThemeService themeService: IThemeService,
61
38
  @IOptionsService private readonly _optionsService: IOptionsService,
62
- @ICharSizeService private readonly _charSizeService: ICharSizeService,
63
- @IRenderService private readonly _renderService: IRenderService,
64
- @ICoreBrowserService private readonly _coreBrowserService: ICoreBrowserService,
65
- @IThemeService themeService: IThemeService
39
+ @IRenderService private readonly _renderService: IRenderService
66
40
  ) {
67
41
  super();
68
42
 
69
- // Measure the width of the scrollbar. If it is 0 we can assume it's an OSX overlay scrollbar.
70
- // Unfortunately the overlay scrollbar would be hidden underneath the screen element in that
71
- // case, therefore we account for a standard amount to make it visible
72
- this.scrollBarWidth = (this._viewportElement.offsetWidth - this._scrollArea.offsetWidth) || FALLBACK_SCROLL_BAR_WIDTH;
73
- this.register(addDisposableDomListener(this._viewportElement, 'scroll', this._handleScroll.bind(this)));
74
-
75
- // Track properties used in performance critical code manually to avoid using slow getters
76
- this._activeBuffer = this._bufferService.buffer;
77
- this.register(this._bufferService.buffers.onBufferActivate(e => this._activeBuffer = e.activeBuffer));
78
- this._renderDimensions = this._renderService.dimensions;
79
- this.register(this._renderService.onDimensionsChange(e => this._renderDimensions = e));
80
-
81
- this._handleThemeChange(themeService.colors);
82
- this.register(themeService.onChangeColors(e => this._handleThemeChange(e)));
83
- this.register(this._optionsService.onSpecificOptionChange('scrollback', () => this.syncScrollArea()));
84
-
85
- // Perform this async to ensure the ICharSizeService is ready.
86
- setTimeout(() => this.syncScrollArea());
87
- }
88
-
89
- private _handleThemeChange(colors: ReadonlyColorSet): void {
90
- this._viewportElement.style.backgroundColor = colors.background.css;
43
+ const scrollable = this._register(new Scrollable({
44
+ forceIntegerValues: false,
45
+ smoothScrollDuration: this._optionsService.rawOptions.smoothScrollDuration,
46
+ // This is used over `IRenderService.addRefreshCallback` since it can be canceled
47
+ scheduleAtNextAnimationFrame: cb => scheduleAtNextAnimationFrame(coreBrowserService.window, cb)
48
+ }));
49
+ this._register(this._optionsService.onSpecificOptionChange('smoothScrollDuration', () => {
50
+ scrollable.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration);
51
+ }));
52
+
53
+ this._scrollableElement = this._register(new SmoothScrollableElement(screenElement, {
54
+ vertical: ScrollbarVisibility.Auto,
55
+ horizontal: ScrollbarVisibility.Hidden,
56
+ useShadows: false,
57
+ mouseWheelSmoothScroll: true,
58
+ ...this._getChangeOptions()
59
+ }, scrollable));
60
+ this._register(this._optionsService.onMultipleOptionChange([
61
+ 'scrollSensitivity',
62
+ 'fastScrollSensitivity',
63
+ 'overviewRuler'
64
+ ], () => this._scrollableElement.updateOptions(this._getChangeOptions())));
65
+ // Don't handle mouse wheel if wheel events are supported by the current mouse prototcol
66
+ this._register(coreMouseService.onProtocolChange(type => {
67
+ this._scrollableElement.updateOptions({
68
+ handleMouseWheel: !(type & CoreMouseEventType.WHEEL)
69
+ });
70
+ }));
71
+
72
+ this._scrollableElement.setScrollDimensions({ height: 0, scrollHeight: 0 });
73
+ this._register(Event.runAndSubscribe(themeService.onChangeColors, () => {
74
+ this._scrollableElement.getDomNode().style.backgroundColor = themeService.colors.background.css;
75
+ }));
76
+ element.appendChild(this._scrollableElement.getDomNode());
77
+ this._register(toDisposable(() => this._scrollableElement.getDomNode().remove()));
78
+
79
+ this._styleElement = coreBrowserService.window.document.createElement('style');
80
+ screenElement.appendChild(this._styleElement);
81
+ this._register(toDisposable(() => this._styleElement.remove()));
82
+ this._register(Event.runAndSubscribe(themeService.onChangeColors, () => {
83
+ this._styleElement.textContent = [
84
+ `.xterm .xterm-scrollable-element > .scrollbar > .slider {`,
85
+ ` background: ${themeService.colors.scrollbarSliderBackground.css};`,
86
+ `}`,
87
+ `.xterm .xterm-scrollable-element > .scrollbar > .slider:hover {`,
88
+ ` background: ${themeService.colors.scrollbarSliderHoverBackground.css};`,
89
+ `}`,
90
+ `.xterm .xterm-scrollable-element > .scrollbar > .slider.active {`,
91
+ ` background: ${themeService.colors.scrollbarSliderActiveBackground.css};`,
92
+ `}`
93
+ ].join('\n');
94
+ }));
95
+
96
+ this._register(this._bufferService.onResize(() => this._queueSync()));
97
+ this._register(this._bufferService.onScroll(() => this._sync()));
98
+
99
+ this._register(this._scrollableElement.onScroll(e => this._handleScroll(e)));
91
100
  }
92
101
 
93
- public reset(): void {
94
- this._currentRowHeight = 0;
95
- this._currentDeviceCellHeight = 0;
96
- this._lastRecordedBufferLength = 0;
97
- this._lastRecordedViewportHeight = 0;
98
- this._lastRecordedBufferHeight = 0;
99
- this._lastTouchY = 0;
100
- this._lastScrollTop = 0;
101
- // Sync on next animation frame to ensure the new terminal state is used
102
- this._coreBrowserService.window.requestAnimationFrame(() => this.syncScrollArea());
102
+ public scrollLines(disp: number): void {
103
+ const pos = this._scrollableElement.getScrollPosition();
104
+ this._scrollableElement.setScrollPosition({
105
+ reuseAnimation: true,
106
+ scrollTop: pos.scrollTop + disp * this._renderService.dimensions.css.cell.height
107
+ });
103
108
  }
104
109
 
105
- /**
106
- * Refreshes row height, setting line-height, viewport height and scroll area height if
107
- * necessary.
108
- */
109
- private _refresh(immediate: boolean): void {
110
- if (immediate) {
111
- this._innerRefresh();
112
- if (this._refreshAnimationFrame !== null) {
113
- this._coreBrowserService.window.cancelAnimationFrame(this._refreshAnimationFrame);
114
- }
115
- return;
116
- }
117
- if (this._refreshAnimationFrame === null) {
118
- this._refreshAnimationFrame = this._coreBrowserService.window.requestAnimationFrame(() => this._innerRefresh());
110
+ public scrollToLine(line: number, disableSmoothScroll?: boolean): void {
111
+ if (disableSmoothScroll) {
112
+ this._latestYDisp = line;
119
113
  }
114
+ this._scrollableElement.setScrollPosition({
115
+ reuseAnimation: !disableSmoothScroll,
116
+ scrollTop: line * this._renderService.dimensions.css.cell.height
117
+ });
120
118
  }
121
119
 
122
- private _innerRefresh(): void {
123
- if (this._charSizeService.height > 0) {
124
- this._currentRowHeight = this._renderDimensions.device.cell.height / this._coreBrowserService.dpr;
125
- this._currentDeviceCellHeight = this._renderDimensions.device.cell.height;
126
- this._lastRecordedViewportHeight = this._viewportElement.offsetHeight;
127
- const newBufferHeight = Math.round(this._currentRowHeight * this._lastRecordedBufferLength) + (this._lastRecordedViewportHeight - this._renderDimensions.css.canvas.height);
128
- if (this._lastRecordedBufferHeight !== newBufferHeight) {
129
- this._lastRecordedBufferHeight = newBufferHeight;
130
- this._scrollArea.style.height = this._lastRecordedBufferHeight + 'px';
131
- }
132
- }
133
-
134
- // Sync scrollTop
135
- const scrollTop = this._bufferService.buffer.ydisp * this._currentRowHeight;
136
- if (this._viewportElement.scrollTop !== scrollTop) {
137
- // Ignore the next scroll event which will be triggered by setting the scrollTop as we do not
138
- // want this event to scroll the terminal
139
- this._ignoreNextScrollEvent = true;
140
- this._viewportElement.scrollTop = scrollTop;
141
- }
142
-
143
- this._refreshAnimationFrame = null;
120
+ private _getChangeOptions(): ScrollableElementChangeOptions {
121
+ return {
122
+ mouseWheelScrollSensitivity: this._optionsService.rawOptions.scrollSensitivity,
123
+ fastScrollSensitivity: this._optionsService.rawOptions.fastScrollSensitivity,
124
+ verticalScrollbarSize: this._optionsService.rawOptions.overviewRuler?.width || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH
125
+ };
144
126
  }
145
127
 
146
- /**
147
- * Updates dimensions and synchronizes the scroll area if necessary.
148
- */
149
- public syncScrollArea(immediate: boolean = false): void {
150
- // If buffer height changed
151
- if (this._lastRecordedBufferLength !== this._bufferService.buffer.lines.length) {
152
- this._lastRecordedBufferLength = this._bufferService.buffer.lines.length;
153
- this._refresh(immediate);
154
- return;
155
- }
156
-
157
- // If viewport height changed
158
- if (this._lastRecordedViewportHeight !== this._renderService.dimensions.css.canvas.height) {
159
- this._refresh(immediate);
160
- return;
128
+ private _queueSync(ydisp?: number): void {
129
+ // Update state
130
+ if (ydisp !== undefined) {
131
+ this._latestYDisp = ydisp;
161
132
  }
162
133
 
163
- // If the buffer position doesn't match last scroll top
164
- if (this._lastScrollTop !== this._activeBuffer.ydisp * this._currentRowHeight) {
165
- this._refresh(immediate);
166
- return;
167
- }
168
-
169
- // If row height changed
170
- if (this._renderDimensions.device.cell.height !== this._currentDeviceCellHeight) {
171
- this._refresh(immediate);
134
+ // Don't queue more than one callback
135
+ if (this._queuedAnimationFrame !== undefined) {
172
136
  return;
173
137
  }
138
+ this._queuedAnimationFrame = this._renderService.addRefreshCallback(() => {
139
+ this._queuedAnimationFrame = undefined;
140
+ this._sync(this._latestYDisp);
141
+ });
174
142
  }
175
143
 
176
- /**
177
- * Handles scroll events on the viewport, calculating the new viewport and requesting the
178
- * terminal to scroll to it.
179
- * @param ev The scroll event.
180
- */
181
- private _handleScroll(ev: Event): void {
182
- // Record current scroll top position
183
- this._lastScrollTop = this._viewportElement.scrollTop;
184
-
185
- // Don't attempt to scroll if the element is not visible, otherwise scrollTop will be corrupt
186
- // which causes the terminal to scroll the buffer to the top
187
- if (!this._viewportElement.offsetParent) {
144
+ private _sync(ydisp: number = this._bufferService.buffer.ydisp): void {
145
+ if (!this._renderService || this._isSyncing) {
188
146
  return;
189
147
  }
148
+ this._isSyncing = true;
190
149
 
191
- // Ignore the event if it was flagged to ignore (when the source of the event is from Viewport)
192
- if (this._ignoreNextScrollEvent) {
193
- this._ignoreNextScrollEvent = false;
194
- // Still trigger the scroll so lines get refreshed
195
- this._onRequestScrollLines.fire({ amount: 0, suppressScrollEvent: true });
196
- return;
197
- }
198
-
199
- const newRow = Math.round(this._lastScrollTop / this._currentRowHeight);
200
- const diff = newRow - this._bufferService.buffer.ydisp;
201
- this._onRequestScrollLines.fire({ amount: diff, suppressScrollEvent: true });
202
- }
150
+ // Ignore any onScroll event that happens as a result of dimensions changing as this should
151
+ // never cause a scrollLines call, only setScrollPosition can do that.
152
+ this._suppressOnScrollHandler = true;
153
+ this._scrollableElement.setScrollDimensions({
154
+ height: this._renderService.dimensions.css.canvas.height,
155
+ scrollHeight: this._renderService.dimensions.css.cell.height * this._bufferService.buffer.lines.length
156
+ });
157
+ this._suppressOnScrollHandler = false;
203
158
 
204
- private _smoothScroll(): void {
205
- // Check valid state
206
- if (this._isDisposed || this._smoothScrollState.origin === -1 || this._smoothScrollState.target === -1) {
207
- return;
159
+ // If ydisp has been changed by some other copmonent (input/buffer), then stop animating smooth
160
+ // scroll and scroll there immediately.
161
+ if (ydisp !== this._latestYDisp) {
162
+ this._scrollableElement.setScrollPosition({
163
+ scrollTop: ydisp * this._renderService.dimensions.css.cell.height
164
+ });
208
165
  }
209
166
 
210
- // Calculate position complete
211
- const percent = this._smoothScrollPercent();
212
- this._viewportElement.scrollTop = this._smoothScrollState.origin + Math.round(percent * (this._smoothScrollState.target - this._smoothScrollState.origin));
213
-
214
- // Continue or finish smooth scroll
215
- if (percent < 1) {
216
- if (!this._smoothScrollAnimationFrame) {
217
- this._smoothScrollAnimationFrame = this._coreBrowserService.window.requestAnimationFrame(() => {
218
- this._smoothScrollAnimationFrame = 0;
219
- this._smoothScroll();
220
- });
221
- }
222
- } else {
223
- this._clearSmoothScrollState();
224
- }
167
+ this._isSyncing = false;
225
168
  }
226
169
 
227
- private _smoothScrollPercent(): number {
228
- if (!this._optionsService.rawOptions.smoothScrollDuration || !this._smoothScrollState.startTime) {
229
- return 1;
230
- }
231
- return Math.max(Math.min((Date.now() - this._smoothScrollState.startTime) / this._optionsService.rawOptions.smoothScrollDuration, 1), 0);
232
- }
233
-
234
- private _clearSmoothScrollState(): void {
235
- this._smoothScrollState.startTime = 0;
236
- this._smoothScrollState.origin = -1;
237
- this._smoothScrollState.target = -1;
238
- }
239
-
240
- /**
241
- * Handles bubbling of scroll event in case the viewport has reached top or bottom
242
- * @param ev The scroll event.
243
- * @param amount The amount scrolled
244
- */
245
- private _bubbleScroll(ev: Event, amount: number): boolean {
246
- const scrollPosFromTop = this._viewportElement.scrollTop + this._lastRecordedViewportHeight;
247
- if ((amount < 0 && this._viewportElement.scrollTop !== 0) ||
248
- (amount > 0 && scrollPosFromTop < this._lastRecordedBufferHeight)) {
249
- if (ev.cancelable) {
250
- ev.preventDefault();
251
- }
252
- return false;
253
- }
254
- return true;
255
- }
256
-
257
- /**
258
- * Handles mouse wheel events by adjusting the viewport's scrollTop and delegating the actual
259
- * scrolling to `onScroll`, this event needs to be attached manually by the consumer of
260
- * `Viewport`.
261
- * @param ev The mouse wheel event.
262
- */
263
- public handleWheel(ev: WheelEvent): boolean {
264
- const amount = this._getPixelsScrolled(ev);
265
- if (amount === 0) {
266
- return false;
267
- }
268
- if (!this._optionsService.rawOptions.smoothScrollDuration) {
269
- this._viewportElement.scrollTop += amount;
270
- } else {
271
- this._smoothScrollState.startTime = Date.now();
272
- if (this._smoothScrollPercent() < 1) {
273
- this._smoothScrollState.origin = this._viewportElement.scrollTop;
274
- if (this._smoothScrollState.target === -1) {
275
- this._smoothScrollState.target = this._viewportElement.scrollTop + amount;
276
- } else {
277
- this._smoothScrollState.target += amount;
278
- }
279
- this._smoothScrollState.target = Math.max(Math.min(this._smoothScrollState.target, this._viewportElement.scrollHeight), 0);
280
- this._smoothScroll();
281
- } else {
282
- this._clearSmoothScrollState();
283
- }
284
- }
285
- return this._bubbleScroll(ev, amount);
286
- }
287
-
288
- public scrollLines(disp: number): void {
289
- if (disp === 0) {
170
+ private _handleScroll(e: ScrollEvent): void {
171
+ if (!this._renderService) {
290
172
  return;
291
173
  }
292
- if (!this._optionsService.rawOptions.smoothScrollDuration) {
293
- this._onRequestScrollLines.fire({ amount: disp, suppressScrollEvent: false });
294
- } else {
295
- const amount = disp * this._currentRowHeight;
296
- this._smoothScrollState.startTime = Date.now();
297
- if (this._smoothScrollPercent() < 1) {
298
- this._smoothScrollState.origin = this._viewportElement.scrollTop;
299
- this._smoothScrollState.target = this._smoothScrollState.origin + amount;
300
- this._smoothScrollState.target = Math.max(Math.min(this._smoothScrollState.target, this._viewportElement.scrollHeight), 0);
301
- this._smoothScroll();
302
- } else {
303
- this._clearSmoothScrollState();
304
- }
305
- }
306
- }
307
-
308
- private _getPixelsScrolled(ev: WheelEvent): number {
309
- // Do nothing if it's not a vertical scroll event
310
- if (ev.deltaY === 0 || ev.shiftKey) {
311
- return 0;
312
- }
313
-
314
- // Fallback to WheelEvent.DOM_DELTA_PIXEL
315
- let amount = this._applyScrollModifier(ev.deltaY, ev);
316
- if (ev.deltaMode === WheelEvent.DOM_DELTA_LINE) {
317
- amount *= this._currentRowHeight;
318
- } else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
319
- amount *= this._currentRowHeight * this._bufferService.rows;
320
- }
321
- return amount;
322
- }
323
-
324
-
325
- public getBufferElements(startLine: number, endLine?: number): { bufferElements: HTMLElement[], cursorElement?: HTMLElement } {
326
- let currentLine: string = '';
327
- let cursorElement: HTMLElement | undefined;
328
- const bufferElements: HTMLElement[] = [];
329
- const end = endLine ?? this._bufferService.buffer.lines.length;
330
- const lines = this._bufferService.buffer.lines;
331
- for (let i = startLine; i < end; i++) {
332
- const line = lines.get(i);
333
- if (!line) {
334
- continue;
335
- }
336
- const isWrapped = lines.get(i + 1)?.isWrapped;
337
- currentLine += line.translateToString(!isWrapped);
338
- if (!isWrapped || i === lines.length - 1) {
339
- const div = document.createElement('div');
340
- div.textContent = currentLine;
341
- bufferElements.push(div);
342
- if (currentLine.length > 0) {
343
- cursorElement = div;
344
- }
345
- currentLine = '';
346
- }
347
- }
348
- return { bufferElements, cursorElement };
349
- }
350
-
351
- /**
352
- * Gets the number of pixels scrolled by the mouse event taking into account what type of delta
353
- * is being used.
354
- * @param ev The mouse wheel event.
355
- */
356
- public getLinesScrolled(ev: WheelEvent): number {
357
- // Do nothing if it's not a vertical scroll event
358
- if (ev.deltaY === 0 || ev.shiftKey) {
359
- return 0;
360
- }
361
-
362
- // Fallback to WheelEvent.DOM_DELTA_LINE
363
- let amount = this._applyScrollModifier(ev.deltaY, ev);
364
- if (ev.deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
365
- amount /= this._currentRowHeight + 0.0; // Prevent integer division
366
- this._wheelPartialScroll += amount;
367
- amount = Math.floor(Math.abs(this._wheelPartialScroll)) * (this._wheelPartialScroll > 0 ? 1 : -1);
368
- this._wheelPartialScroll %= 1;
369
- } else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
370
- amount *= this._bufferService.rows;
371
- }
372
- return amount;
373
- }
374
-
375
- private _applyScrollModifier(amount: number, ev: WheelEvent): number {
376
- const modifier = this._optionsService.rawOptions.fastScrollModifier;
377
- // Multiply the scroll speed when the modifier is down
378
- if ((modifier === 'alt' && ev.altKey) ||
379
- (modifier === 'ctrl' && ev.ctrlKey) ||
380
- (modifier === 'shift' && ev.shiftKey)) {
381
- return amount * this._optionsService.rawOptions.fastScrollSensitivity * this._optionsService.rawOptions.scrollSensitivity;
174
+ if (this._isHandlingScroll || this._suppressOnScrollHandler) {
175
+ return;
382
176
  }
383
-
384
- return amount * this._optionsService.rawOptions.scrollSensitivity;
385
- }
386
-
387
- /**
388
- * Handles the touchstart event, recording the touch occurred.
389
- * @param ev The touch event.
390
- */
391
- public handleTouchStart(ev: TouchEvent): void {
392
- this._lastTouchY = ev.touches[0].pageY;
393
- }
394
-
395
- /**
396
- * Handles the touchmove event, scrolling the viewport if the position shifted.
397
- * @param ev The touch event.
398
- */
399
- public handleTouchMove(ev: TouchEvent): boolean {
400
- const deltaY = this._lastTouchY - ev.touches[0].pageY;
401
- this._lastTouchY = ev.touches[0].pageY;
402
- if (deltaY === 0) {
403
- return false;
177
+ this._isHandlingScroll = true;
178
+ const newRow = Math.round(e.scrollTop / this._renderService.dimensions.css.cell.height);
179
+ const diff = newRow - this._bufferService.buffer.ydisp;
180
+ if (diff !== 0) {
181
+ this._latestYDisp = newRow;
182
+ this._onRequestScrollLines.fire(diff);
404
183
  }
405
- this._viewportElement.scrollTop += deltaY;
406
- return this._bubbleScroll(ev, deltaY);
184
+ this._isHandlingScroll = false;
407
185
  }
408
186
  }
@@ -4,7 +4,7 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
 
6
6
  import { ICoreBrowserService, IRenderService } from 'browser/services/Services';
7
- import { Disposable, toDisposable } from 'common/Lifecycle';
7
+ import { Disposable, toDisposable } from 'vs/base/common/lifecycle';
8
8
  import { IBufferService, IDecorationService, IInternalDecoration } from 'common/services/Services';
9
9
 
10
10
  export class BufferDecorationRenderer extends Disposable {
@@ -28,18 +28,18 @@ export class BufferDecorationRenderer extends Disposable {
28
28
  this._container.classList.add('xterm-decoration-container');
29
29
  this._screenElement.appendChild(this._container);
30
30
 
31
- this.register(this._renderService.onRenderedViewportChange(() => this._doRefreshDecorations()));
32
- this.register(this._renderService.onDimensionsChange(() => {
31
+ this._register(this._renderService.onRenderedViewportChange(() => this._doRefreshDecorations()));
32
+ this._register(this._renderService.onDimensionsChange(() => {
33
33
  this._dimensionsChanged = true;
34
34
  this._queueRefresh();
35
35
  }));
36
- this.register(this._coreBrowserService.onDprChange(() => this._queueRefresh()));
37
- this.register(this._bufferService.buffers.onBufferActivate(() => {
36
+ this._register(this._coreBrowserService.onDprChange(() => this._queueRefresh()));
37
+ this._register(this._bufferService.buffers.onBufferActivate(() => {
38
38
  this._altBufferIsActive = this._bufferService.buffer === this._bufferService.buffers.alt;
39
39
  }));
40
- this.register(this._decorationService.onDecorationRegistered(() => this._queueRefresh()));
41
- this.register(this._decorationService.onDecorationRemoved(decoration => this._removeDecoration(decoration)));
42
- this.register(toDisposable(() => {
40
+ this._register(this._decorationService.onDecorationRegistered(() => this._queueRefresh()));
41
+ this._register(this._decorationService.onDecorationRemoved(decoration => this._removeDecoration(decoration)));
42
+ this._register(toDisposable(() => {
43
43
  this._container.remove();
44
44
  this._decorationElements.clear();
45
45
  }));
@@ -108,8 +108,13 @@ export class BufferDecorationRenderer extends Disposable {
108
108
  element!.remove();
109
109
  });
110
110
  }
111
- element.style.top = `${line * this._renderService.dimensions.css.cell.height}px`;
112
111
  element.style.display = this._altBufferIsActive ? 'none' : 'block';
112
+ if (!this._altBufferIsActive) {
113
+ element.style.width = `${Math.round((decoration.options.width || 1) * this._renderService.dimensions.css.cell.width)}px`;
114
+ element.style.height = `${(decoration.options.height || 1) * this._renderService.dimensions.css.cell.height}px`;
115
+ element.style.top = `${line * this._renderService.dimensions.css.cell.height}px`;
116
+ element.style.lineHeight = `${this._renderService.dimensions.css.cell.height}px`;
117
+ }
113
118
  decoration.onRenderEmitter.fire(element);
114
119
  }
115
120
  }