@xterm/xterm 5.4.0-beta.15 → 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/lib/xterm.js +1 -1
- package/lib/xterm.js.map +1 -1
- package/package.json +1 -1
- package/src/browser/Terminal.ts +13 -10
- package/src/browser/Types.d.ts +1 -0
- package/src/browser/public/Terminal.ts +3 -0
- package/typings/xterm.d.ts +22 -0
package/package.json
CHANGED
package/src/browser/Terminal.ts
CHANGED
|
@@ -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
|
}
|
package/src/browser/Types.d.ts
CHANGED
|
@@ -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
|
}
|
package/typings/xterm.d.ts
CHANGED
|
@@ -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
|