@xterm/xterm 6.1.0-beta.183 → 6.1.0-beta.185

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.
@@ -15,7 +15,7 @@ import { IParsingState, IEscapeSequenceParser, IParams, IFunctionIdentifier } fr
15
15
  import { NULL_CELL_CODE, NULL_CELL_WIDTH, Attributes, FgFlags, BgFlags, Content, UnderlineStyle } from 'common/buffer/Constants';
16
16
  import { CellData } from 'common/buffer/CellData';
17
17
  import { AttributeData } from 'common/buffer/AttributeData';
18
- import { ICoreService, IBufferService, IOptionsService, ILogService, ICoreMouseService, ICharsetService, IUnicodeService, LogLevelEnum, IOscLinkService } from 'common/services/Services';
18
+ import { ICoreService, IBufferService, IOptionsService, ILogService, IMouseStateService, ICharsetService, IUnicodeService, LogLevelEnum, IOscLinkService } from 'common/services/Services';
19
19
  import { UnicodeService } from 'common/services/UnicodeService';
20
20
  import { OscHandler } from 'common/parser/OscParser';
21
21
  import { DcsHandler } from 'common/parser/DcsParser';
@@ -178,7 +178,7 @@ export class InputHandler extends Disposable implements IInputHandler {
178
178
  private readonly _logService: ILogService,
179
179
  private readonly _optionsService: IOptionsService,
180
180
  private readonly _oscLinkService: IOscLinkService,
181
- private readonly _coreMouseService: ICoreMouseService,
181
+ private readonly _mouseStateService: IMouseStateService,
182
182
  private readonly _unicodeService: IUnicodeService,
183
183
  private readonly _parser: IEscapeSequenceParser = new EscapeSequenceParser()
184
184
  ) {
@@ -1987,19 +1987,19 @@ export class InputHandler extends Disposable implements IInputHandler {
1987
1987
  break;
1988
1988
  case 9: // X10 Mouse
1989
1989
  // no release, no motion, no wheel, no modifiers.
1990
- this._coreMouseService.activeProtocol = 'X10';
1990
+ this._mouseStateService.activeProtocol = 'X10';
1991
1991
  break;
1992
1992
  case 1000: // vt200 mouse
1993
1993
  // no motion.
1994
- this._coreMouseService.activeProtocol = 'VT200';
1994
+ this._mouseStateService.activeProtocol = 'VT200';
1995
1995
  break;
1996
1996
  case 1002: // button event mouse
1997
- this._coreMouseService.activeProtocol = 'DRAG';
1997
+ this._mouseStateService.activeProtocol = 'DRAG';
1998
1998
  break;
1999
1999
  case 1003: // any event mouse
2000
2000
  // any event - sends motion events,
2001
2001
  // even if there is no button held down.
2002
- this._coreMouseService.activeProtocol = 'ANY';
2002
+ this._mouseStateService.activeProtocol = 'ANY';
2003
2003
  break;
2004
2004
  case 1004: // send focusin/focusout events
2005
2005
  // focusin: ^[[I
@@ -2011,13 +2011,13 @@ export class InputHandler extends Disposable implements IInputHandler {
2011
2011
  this._logService.debug('DECSET 1005 not supported (see #2507)');
2012
2012
  break;
2013
2013
  case 1006: // sgr ext mode mouse
2014
- this._coreMouseService.activeEncoding = 'SGR';
2014
+ this._mouseStateService.activeEncoding = 'SGR';
2015
2015
  break;
2016
2016
  case 1015: // urxvt ext mode mouse - removed in #2507
2017
2017
  this._logService.debug('DECSET 1015 not supported (see #2507)');
2018
2018
  break;
2019
2019
  case 1016: // sgr pixels mode mouse
2020
- this._coreMouseService.activeEncoding = 'SGR_PIXELS';
2020
+ this._mouseStateService.activeEncoding = 'SGR_PIXELS';
2021
2021
  break;
2022
2022
  case 25: // show cursor
2023
2023
  this._coreService.isCursorHidden = false;
@@ -2248,7 +2248,7 @@ export class InputHandler extends Disposable implements IInputHandler {
2248
2248
  case 1000: // vt200 mouse
2249
2249
  case 1002: // button event mouse
2250
2250
  case 1003: // any event mouse
2251
- this._coreMouseService.activeProtocol = 'NONE';
2251
+ this._mouseStateService.activeProtocol = 'NONE';
2252
2252
  break;
2253
2253
  case 1004: // send focusin/focusout events
2254
2254
  this._coreService.decPrivateModes.sendFocus = false;
@@ -2257,13 +2257,13 @@ export class InputHandler extends Disposable implements IInputHandler {
2257
2257
  this._logService.debug('DECRST 1005 not supported (see #2507)');
2258
2258
  break;
2259
2259
  case 1006: // sgr ext mode mouse
2260
- this._coreMouseService.activeEncoding = 'DEFAULT';
2260
+ this._mouseStateService.activeEncoding = 'DEFAULT';
2261
2261
  break;
2262
2262
  case 1015: // urxvt ext mode mouse - removed in #2507
2263
2263
  this._logService.debug('DECRST 1015 not supported (see #2507)');
2264
2264
  break;
2265
2265
  case 1016: // sgr pixels mode mouse
2266
- this._coreMouseService.activeEncoding = 'DEFAULT';
2266
+ this._mouseStateService.activeEncoding = 'DEFAULT';
2267
2267
  break;
2268
2268
  case 25: // hide cursor
2269
2269
  this._coreService.isCursorHidden = true;
@@ -2357,7 +2357,7 @@ export class InputHandler extends Disposable implements IInputHandler {
2357
2357
 
2358
2358
  // access helpers
2359
2359
  const dm = this._coreService.decPrivateModes;
2360
- const { activeProtocol: mouseProtocol, activeEncoding: mouseEncoding } = this._coreMouseService;
2360
+ const { activeProtocol: mouseProtocol, activeEncoding: mouseEncoding } = this._mouseStateService;
2361
2361
  const cs = this._coreService;
2362
2362
  const { buffers, cols } = this._bufferService;
2363
2363
  const { active, alt } = buffers;
@@ -7,12 +7,12 @@ import { IDeleteEvent, IInsertEvent } from 'common/CircularList';
7
7
  import { UnderlineStyle } from 'common/buffer/Constants';
8
8
  import { IBufferSet } from 'common/buffer/Types';
9
9
  import { IParams } from 'common/parser/Types';
10
- import { ICoreMouseService, ICoreService, IOptionsService, IUnicodeService } from 'common/services/Services';
10
+ import { IMouseStateService, ICoreService, IOptionsService, IUnicodeService } from 'common/services/Services';
11
11
  import { IFunctionIdentifier, ITerminalOptions as IPublicTerminalOptions } from '@xterm/xterm';
12
12
  import type { Emitter, IEvent } from 'common/Event';
13
13
 
14
14
  export interface ICoreTerminal {
15
- coreMouseService: ICoreMouseService;
15
+ mouseStateService: IMouseStateService;
16
16
  coreService: ICoreService;
17
17
  optionsService: IOptionsService;
18
18
  unicodeService: IUnicodeService;
@@ -343,7 +343,7 @@ export interface ICoreMouseEvent {
343
343
  * it is not possible to report multiple buttons at once.
344
344
  * Wheel is treated as a button.
345
345
  * There are invalid combinations of buttons and actions possible
346
- * (like move + wheel), those are silently ignored by the CoreMouseService.
346
+ * (like move + wheel), those are silently ignored by the MouseStateService.
347
347
  */
348
348
  button: CoreMouseButton;
349
349
  action: CoreMouseAction;
@@ -360,7 +360,7 @@ export interface ICoreMouseEvent {
360
360
  * CoreMouseEventType
361
361
  * To be reported to the browser component which events a mouse
362
362
  * protocol wants to be catched and forwarded as an ICoreMouseEvent
363
- * to CoreMouseService.
363
+ * to MouseStateService.
364
364
  */
365
365
  export const enum CoreMouseEventType {
366
366
  NONE = 0,
@@ -378,7 +378,7 @@ export const enum CoreMouseEventType {
378
378
 
379
379
  /**
380
380
  * Mouse protocol interface.
381
- * A mouse protocol can be registered and activated at the CoreMouseService.
381
+ * A mouse protocol can be registered and activated at the MouseStateService.
382
382
  * `events` should contain a list of needed events as a hint for the browser component
383
383
  * to install/remove the appropriate event handlers.
384
384
  * `restrict` applies further protocol specific restrictions like not allowed
@@ -391,7 +391,7 @@ export interface ICoreMouseProtocol {
391
391
 
392
392
  /**
393
393
  * CoreMouseEncoding
394
- * The tracking encoding can be registered and activated at the CoreMouseService.
394
+ * The tracking encoding can be registered and activated at the MouseStateService.
395
395
  * If a ICoreMouseEvent passes all procotol restrictions it will be encoded
396
396
  * with the active encoding and sent out.
397
397
  * Note: Returning an empty string will supress sending a mouse report,
@@ -6,4 +6,4 @@
6
6
  /**
7
7
  * The xterm.js version. This is updated by the publish script from package.json.
8
8
  */
9
- export const XTERM_VERSION = '6.1.0-beta.183';
9
+ export const XTERM_VERSION = '6.1.0-beta.185';
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2019 The xterm.js authors. All rights reserved.
3
3
  * @license MIT
4
4
  */
5
- import { IBufferService, ICoreService, ICoreMouseService, IOptionsService } from 'common/services/Services';
5
+ import { IMouseStateService } from 'common/services/Services';
6
6
  import { ICoreMouseProtocol, ICoreMouseEvent, CoreMouseEncoding, CoreMouseEventType, CoreMouseButton, CoreMouseAction } from 'common/Types';
7
7
  import { Disposable } from 'common/Lifecycle';
8
8
  import { Emitter } from 'common/Event';
@@ -151,7 +151,7 @@ const DEFAULT_ENCODINGS: { [key: string]: CoreMouseEncoding } = {
151
151
  };
152
152
 
153
153
  /**
154
- * CoreMouseService
154
+ * MouseStateService
155
155
  *
156
156
  * Provides mouse tracking reports with different protocols and encodings.
157
157
  * - protocols: NONE (default), X10, VT200, DRAG, ANY
@@ -166,25 +166,21 @@ const DEFAULT_ENCODINGS: { [key: string]: CoreMouseEncoding } = {
166
166
  * a tracking report to the backend based on protocol and encoding limitations.
167
167
  * To send a mouse event call `triggerMouseEvent`.
168
168
  */
169
- export class CoreMouseService extends Disposable implements ICoreMouseService {
169
+ export class MouseStateService extends Disposable implements IMouseStateService {
170
170
  public serviceBrand: any;
171
171
 
172
172
  private _protocols: { [name: string]: ICoreMouseProtocol } = {};
173
173
  private _encodings: { [name: string]: CoreMouseEncoding } = {};
174
174
  private _activeProtocol: string = '';
175
175
  private _activeEncoding: string = '';
176
- private _lastEvent: ICoreMouseEvent | null = null;
177
- private _wheelPartialScroll: number = 0;
176
+ private _customWheelEventHandler: ((event: WheelEvent) => boolean) | undefined;
178
177
 
179
178
  private readonly _onProtocolChange = this._register(new Emitter<CoreMouseEventType>());
180
179
  public readonly onProtocolChange = this._onProtocolChange.event;
181
180
 
182
- constructor(
183
- @IBufferService private readonly _bufferService: IBufferService,
184
- @ICoreService private readonly _coreService: ICoreService,
185
- @IOptionsService private readonly _optionsService: IOptionsService
186
- ) {
181
+ constructor() {
187
182
  super();
183
+
188
184
  // register default protocols and encodings
189
185
  for (const name of Object.keys(DEFAULT_PROTOCOLS)) this.addProtocol(name, DEFAULT_PROTOCOLS[name]);
190
186
  for (const name of Object.keys(DEFAULT_ENCODINGS)) this.addEncoding(name, DEFAULT_ENCODINGS[name]);
@@ -230,136 +226,29 @@ export class CoreMouseService extends Disposable implements ICoreMouseService {
230
226
  public reset(): void {
231
227
  this.activeProtocol = 'NONE';
232
228
  this.activeEncoding = 'DEFAULT';
233
- this._lastEvent = null;
234
- this._wheelPartialScroll = 0;
235
229
  }
236
230
 
237
- /**
238
- * Processes a wheel event, accounting for partial scrolls for trackpad, mouse scrolls.
239
- * This prevents hyper-sensitive scrolling in alt buffer.
240
- */
241
- public consumeWheelEvent(ev: WheelEvent, cellHeight?: number, dpr?: number): number {
242
- // Do nothing if it's not a vertical scroll event
243
- if (ev.deltaY === 0 || ev.shiftKey) {
244
- return 0;
245
- }
246
-
247
- if (cellHeight === undefined || dpr === undefined) {
248
- return 0;
249
- }
250
-
251
- const targetWheelEventPixels = cellHeight / dpr;
252
- let amount = this._applyScrollModifier(ev.deltaY, ev);
253
-
254
- if (ev.deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
255
- amount /= (targetWheelEventPixels + 0.0); // Prevent integer division
256
-
257
- const isLikelyTrackpad = Math.abs(ev.deltaY) < 50;
258
- if (isLikelyTrackpad) {
259
- amount *= 0.3;
260
- }
261
-
262
- this._wheelPartialScroll += amount;
263
- amount = Math.floor(Math.abs(this._wheelPartialScroll)) * (this._wheelPartialScroll > 0 ? 1 : -1);
264
- this._wheelPartialScroll %= 1;
265
- } else if (ev.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
266
- amount *= this._bufferService.rows;
267
- }
268
- return amount;
231
+ public setCustomWheelEventHandler(customWheelEventHandler: ((event: WheelEvent) => boolean) | undefined): void {
232
+ this._customWheelEventHandler = customWheelEventHandler;
269
233
  }
270
234
 
271
- private _applyScrollModifier(amount: number, ev: WheelEvent): number {
272
- // Multiply the scroll speed when the modifier key is pressed
273
- if (ev.altKey || ev.ctrlKey || ev.shiftKey) {
274
- return amount * this._optionsService.rawOptions.fastScrollSensitivity * this._optionsService.rawOptions.scrollSensitivity;
275
- }
276
- return amount * this._optionsService.rawOptions.scrollSensitivity;
235
+ public allowCustomWheelEvent(ev: WheelEvent): boolean {
236
+ return this._customWheelEventHandler ? this._customWheelEventHandler(ev) !== false : true;
277
237
  }
278
238
 
279
- /**
280
- * Triggers a mouse event to be sent.
281
- *
282
- * Returns true if the event passed all protocol restrictions and a report
283
- * was sent, otherwise false. The return value may be used to decide whether
284
- * the default event action in the bowser component should be omitted.
285
- *
286
- * Note: The method will change values of the given event object
287
- * to fullfill protocol and encoding restrictions.
288
- */
289
- public triggerMouseEvent(e: ICoreMouseEvent): boolean {
290
- // range check for col/row
291
- if (e.col < 0 || e.col >= this._bufferService.cols
292
- || e.row < 0 || e.row >= this._bufferService.rows) {
293
- return false;
294
- }
295
-
296
- // filter nonsense combinations of button + action
297
- if (e.button === CoreMouseButton.WHEEL && e.action === CoreMouseAction.MOVE) {
298
- return false;
299
- }
300
- if (e.button === CoreMouseButton.NONE && e.action !== CoreMouseAction.MOVE) {
301
- return false;
302
- }
303
- if (e.button !== CoreMouseButton.WHEEL && (e.action === CoreMouseAction.LEFT || e.action === CoreMouseAction.RIGHT)) {
304
- return false;
305
- }
306
-
307
- // report 1-based coords
308
- e.col++;
309
- e.row++;
310
-
311
- // debounce move events at grid or pixel level
312
- if (e.action === CoreMouseAction.MOVE
313
- && this._lastEvent
314
- && this._equalEvents(this._lastEvent, e, this._activeEncoding === 'SGR_PIXELS')
315
- ) {
316
- return false;
317
- }
318
-
319
- // apply protocol restrictions
320
- if (!this._protocols[this._activeProtocol].restrict(e)) {
321
- return false;
322
- }
323
-
324
- // encode report and send
325
- const report = this._encodings[this._activeEncoding](e);
326
- if (report) {
327
- // always send DEFAULT as binary data
328
- if (this._activeEncoding === 'DEFAULT') {
329
- this._coreService.triggerBinaryEvent(report);
330
- } else {
331
- this._coreService.triggerDataEvent(report, true);
332
- }
333
- }
334
-
335
- this._lastEvent = e;
239
+ public restrictMouseEvent(e: ICoreMouseEvent): boolean {
240
+ return this._protocols[this._activeProtocol].restrict(e);
241
+ }
336
242
 
337
- return true;
243
+ public encodeMouseEvent(e: ICoreMouseEvent): string {
244
+ return this._encodings[this._activeEncoding](e);
338
245
  }
339
246
 
340
- public explainEvents(events: CoreMouseEventType): { [event: string]: boolean } {
341
- return {
342
- down: !!(events & CoreMouseEventType.DOWN),
343
- up: !!(events & CoreMouseEventType.UP),
344
- drag: !!(events & CoreMouseEventType.DRAG),
345
- move: !!(events & CoreMouseEventType.MOVE),
346
- wheel: !!(events & CoreMouseEventType.WHEEL)
347
- };
247
+ public get isDefaultEncoding(): boolean {
248
+ return this._activeEncoding === 'DEFAULT';
348
249
  }
349
250
 
350
- private _equalEvents(e1: ICoreMouseEvent, e2: ICoreMouseEvent, pixels: boolean): boolean {
351
- if (pixels) {
352
- if (e1.x !== e2.x) return false;
353
- if (e1.y !== e2.y) return false;
354
- } else {
355
- if (e1.col !== e2.col) return false;
356
- if (e1.row !== e2.row) return false;
357
- }
358
- if (e1.button !== e2.button) return false;
359
- if (e1.action !== e2.action) return false;
360
- if (e1.ctrl !== e2.ctrl) return false;
361
- if (e1.alt !== e2.alt) return false;
362
- if (e1.shift !== e2.shift) return false;
363
- return true;
251
+ public get isPixelEncoding(): boolean {
252
+ return this._activeEncoding === 'SGR_PIXELS';
364
253
  }
365
254
  }
@@ -33,8 +33,8 @@ export interface IBufferResizeEvent {
33
33
  rowsChanged: boolean;
34
34
  }
35
35
 
36
- export const ICoreMouseService = createDecorator<ICoreMouseService>('CoreMouseService');
37
- export interface ICoreMouseService {
36
+ export const IMouseStateService = createDecorator<IMouseStateService>('MouseStateService');
37
+ export interface IMouseStateService {
38
38
  serviceBrand: undefined;
39
39
 
40
40
  activeProtocol: string;
@@ -43,33 +43,17 @@ export interface ICoreMouseService {
43
43
  addProtocol(name: string, protocol: ICoreMouseProtocol): void;
44
44
  addEncoding(name: string, encoding: CoreMouseEncoding): void;
45
45
  reset(): void;
46
-
47
- /**
48
- * Triggers a mouse event to be sent.
49
- *
50
- * Returns true if the event passed all protocol restrictions and a report
51
- * was sent, otherwise false. The return value may be used to decide whether
52
- * the default event action in the bowser component should be omitted.
53
- *
54
- * Note: The method will change values of the given event object
55
- * to fullfill protocol and encoding restrictions.
56
- */
57
- triggerMouseEvent(event: ICoreMouseEvent): boolean;
46
+ setCustomWheelEventHandler(customWheelEventHandler: ((event: WheelEvent) => boolean) | undefined): void;
47
+ allowCustomWheelEvent(ev: WheelEvent): boolean;
58
48
 
59
49
  /**
60
50
  * Event to announce changes in mouse tracking.
61
51
  */
62
52
  onProtocolChange: IEvent<CoreMouseEventType>;
63
-
64
- /**
65
- * Human readable version of mouse events.
66
- */
67
- explainEvents(events: CoreMouseEventType): { [event: string]: boolean };
68
-
69
- /**
70
- * Process wheel event taking partial scroll into account.
71
- */
72
- consumeWheelEvent(ev: WheelEvent, cellHeight?: number, dpr?: number): number;
53
+ restrictMouseEvent(event: ICoreMouseEvent): boolean;
54
+ encodeMouseEvent(event: ICoreMouseEvent): string;
55
+ readonly isDefaultEncoding: boolean;
56
+ readonly isPixelEncoding: boolean;
73
57
  }
74
58
 
75
59
  export const ICoreService = createDecorator<ICoreService>('CoreService');