@xterm/xterm 5.4.0-beta.14 → 5.4.0-beta.16

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xterm/xterm",
3
3
  "description": "Full xterm terminal, in your browser",
4
- "version": "5.4.0-beta.14",
4
+ "version": "5.4.0-beta.16",
5
5
  "main": "lib/xterm.js",
6
6
  "style": "css/xterm.css",
7
7
  "types": "typings/xterm.d.ts",
@@ -39,6 +39,9 @@ export class Linkifier2 extends Disposable implements ILinkifier2 {
39
39
  this.register(getDisposeArrayDisposable(this._linkCacheDisposables));
40
40
  this.register(toDisposable(() => {
41
41
  this._lastMouseEvent = undefined;
42
+ // Clear out link providers as they could easily cause an embedder memory leak
43
+ this._linkProviders.length = 0;
44
+ this._activeProviderReplies?.clear();
42
45
  }));
43
46
  // Listen to resize to catch the case where it's resized and the cursor is out of the viewport.
44
47
  this.register(this._bufferService.onResize(() => {
@@ -26,7 +26,7 @@ import { addDisposableDomListener } from 'browser/Lifecycle';
26
26
  import { Linkifier2 } from 'browser/Linkifier2';
27
27
  import * as Strings from 'browser/LocalizableStrings';
28
28
  import { OscLinkProvider } from 'browser/OscLinkProvider';
29
- import { CharacterJoinerHandler, CustomKeyEventHandler, IBrowser, IBufferRange, ICompositionHelper, ILinkifier2, ITerminal, IViewport } from 'browser/Types';
29
+ import { CharacterJoinerHandler, CustomKeyEventHandler, CustomWheelEventHandler, IBrowser, IBufferRange, ICompositionHelper, ILinkifier2, ITerminal, IViewport } from 'browser/Types';
30
30
  import { Viewport } from 'browser/Viewport';
31
31
  import { BufferDecorationRenderer } from 'browser/decorations/BufferDecorationRenderer';
32
32
  import { OverviewRulerRenderer } from 'browser/decorations/OverviewRulerRenderer';
@@ -74,6 +74,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
74
74
  public browser: IBrowser = Browser as any;
75
75
 
76
76
  private _customKeyEventHandler: CustomKeyEventHandler | undefined;
77
+ private _customWheelEventHandler: CustomWheelEventHandler | undefined;
77
78
 
78
79
  // browser services
79
80
  private _decorationService: DecorationService;
@@ -633,6 +634,9 @@ export class Terminal extends CoreTerminal implements ITerminal {
633
634
  but = ev.button < 3 ? ev.button : CoreMouseButton.NONE;
634
635
  break;
635
636
  case 'wheel':
637
+ if (self._customWheelEventHandler && self._customWheelEventHandler(ev as WheelEvent) === false) {
638
+ return false;
639
+ }
636
640
  const amount = self.viewport!.getLinesScrolled(ev as WheelEvent);
637
641
 
638
642
  if (amount === 0) {
@@ -792,6 +796,10 @@ export class Terminal extends CoreTerminal implements ITerminal {
792
796
  // do nothing, if app side handles wheel itself
793
797
  if (requestedEvents.wheel) return;
794
798
 
799
+ if (this._customWheelEventHandler && this._customWheelEventHandler(ev) === false) {
800
+ return false;
801
+ }
802
+
795
803
  if (!this.buffer.hasScrollback) {
796
804
  // Convert wheel events into up/down events when the buffer does not have scrollback, this
797
805
  // enables scrolling in apps hosted in the alt buffer such as vim or tmux.
@@ -878,19 +886,14 @@ export class Terminal extends CoreTerminal implements ITerminal {
878
886
  paste(data, this.textarea!, this.coreService, this.optionsService);
879
887
  }
880
888
 
881
- /**
882
- * Attaches a custom key event handler which is run before keys are processed,
883
- * giving consumers of xterm.js ultimate control as to what keys should be
884
- * processed by the terminal and what keys should not.
885
- * @param customKeyEventHandler The custom KeyboardEvent handler to attach.
886
- * This is a function that takes a KeyboardEvent, allowing consumers to stop
887
- * propagation and/or prevent the default action. The function returns whether
888
- * the event should be processed by xterm.js.
889
- */
890
889
  public attachCustomKeyEventHandler(customKeyEventHandler: CustomKeyEventHandler): void {
891
890
  this._customKeyEventHandler = customKeyEventHandler;
892
891
  }
893
892
 
893
+ public attachCustomWheelEventHandler(customWheelEventHandler: CustomWheelEventHandler): void {
894
+ this._customWheelEventHandler = customWheelEventHandler;
895
+ }
896
+
894
897
  public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {
895
898
  return this.linkifier2.registerLinkProvider(linkProvider);
896
899
  }
@@ -32,6 +32,7 @@ export interface ITerminal extends InternalPassthroughApis, ICoreTerminal {
32
32
  }
33
33
 
34
34
  export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;
35
+ export type CustomWheelEventHandler = (event: WheelEvent) => boolean;
35
36
 
36
37
  export type LineData = CharData[];
37
38
 
@@ -148,6 +148,9 @@ export class Terminal extends Disposable implements ITerminalApi {
148
148
  public attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void {
149
149
  this._core.attachCustomKeyEventHandler(customKeyEventHandler);
150
150
  }
151
+ public attachCustomWheelEventHandler(customWheelEventHandler: (event: WheelEvent) => boolean): void {
152
+ this._core.attachCustomWheelEventHandler(customWheelEventHandler);
153
+ }
151
154
  public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {
152
155
  return this._core.registerLinkProvider(linkProvider);
153
156
  }
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { EventEmitter } from 'common/EventEmitter';
7
- import { Disposable } from 'common/Lifecycle';
7
+ import { Disposable, toDisposable } from 'common/Lifecycle';
8
8
  import { isMac } from 'common/Platform';
9
9
  import { CursorStyle, IDisposable } from 'common/Types';
10
10
  import { FontWeight, IOptionsService, ITerminalOptions } from 'common/services/Services';
@@ -86,6 +86,13 @@ export class OptionsService extends Disposable implements IOptionsService {
86
86
  this.rawOptions = defaultOptions;
87
87
  this.options = { ... defaultOptions };
88
88
  this._setupOptions();
89
+
90
+ // Clear out options that could link outside xterm.js as they could easily cause an embedder
91
+ // memory leak
92
+ this.register(toDisposable(() => {
93
+ this.rawOptions.linkHandler = null;
94
+ this.rawOptions.documentOverride = null;
95
+ }));
89
96
  }
90
97
 
91
98
  // eslint-disable-next-line @typescript-eslint/naming-convention
@@ -1010,6 +1010,28 @@ declare module '@xterm/xterm' {
1010
1010
  */
1011
1011
  attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
1012
1012
 
1013
+ /**
1014
+ * Attaches a custom wheel event handler which is run before keys are
1015
+ * processed, giving consumers of xterm.js control over whether to proceed
1016
+ * or cancel terminal wheel events.
1017
+ * @param customMouseEventHandler The custom WheelEvent handler to attach.
1018
+ * This is a function that takes a WheelEvent, allowing consumers to stop
1019
+ * propagation and/or prevent the default action. The function returns
1020
+ * whether the event should be processed by xterm.js.
1021
+ *
1022
+ * @example A handler that prevents all wheel events while ctrl is held from
1023
+ * being processed.
1024
+ * ```ts
1025
+ * term.attachCustomKeyEventHandler(ev => {
1026
+ * if (ev.ctrlKey) {
1027
+ * return false;
1028
+ * }
1029
+ * return true;
1030
+ * });
1031
+ * ```
1032
+ */
1033
+ attachCustomWheelEventHandler(customWheelEventHandler: (event: WheelEvent) => boolean): void;
1034
+
1013
1035
  /**
1014
1036
  * Registers a link provider, allowing a custom parser to be used to match
1015
1037
  * and handle links. Multiple link providers can be used, they will be asked