first commit
This commit is contained in:
28
xterminal/source/renderer/events.ts
Normal file
28
xterminal/source/renderer/events.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { IDisposable } from "../types";
|
||||
|
||||
export const ENTER_KEY = "Enter",
|
||||
TAB_KEY = "Tab",
|
||||
ARROW_UP_KEY = "ArrowUp",
|
||||
ARROW_DOWN_KEY = "ArrowDown";
|
||||
|
||||
/**
|
||||
* Attaches an event listener to the element returning a disposable object
|
||||
* to remove the event listener
|
||||
*/
|
||||
export function addEvent(
|
||||
el: Element | Document | Window | VisualViewport | EventTarget,
|
||||
type: string,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
handler: (e: any) => void,
|
||||
opt?: boolean | AddEventListenerOptions
|
||||
): IDisposable {
|
||||
el.addEventListener(type, handler, opt);
|
||||
let disposed = false;
|
||||
return {
|
||||
dispose() {
|
||||
if (disposed) return;
|
||||
el.removeEventListener(type, handler, opt);
|
||||
disposed = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user