Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow hooking or disabling paste events #1803

Closed
Eugeny opened this issue Nov 28, 2018 · 4 comments
Closed

Allow hooking or disabling paste events #1803

Eugeny opened this issue Nov 28, 2018 · 4 comments
Labels
needs more info type/enhancement Features or improvements to existing features

Comments

@Eugeny
Copy link
Member

Eugeny commented Nov 28, 2018

I'm currently handling paste myself, but it seems that it's impossible to disable xterm's internal paste handlers. The attached event handlers are irremovable, and pasteHandler isn't exported.

Could you please add an option to disable default paste handlers, or an access point to override its behaviour?

@Tyriar Tyriar added the type/enhancement Features or improvements to existing features label Nov 28, 2018
@Tyriar
Copy link
Member

Tyriar commented Dec 10, 2018

Can you listen for paste using this API and handle it on your end that way?

xterm.js/typings/xterm.d.ts

Lines 473 to 482 in b5f1c33

/**
* Attaches a custom key event handler which is run before keys are
* processed, giving consumers of xterm.js ultimate control as to what keys
* should be processed by the terminal and what keys should not.
* @param customKeyEventHandler The custom KeyboardEvent handler to attach.
* This is a function that takes a KeyboardEvent, allowing consumers to stop
* propogation and/or prevent the default action. The function returns
* whether the event should be processed by xterm.js.
*/
attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;

This is how VS Code does it.

@Eugeny
Copy link
Member Author

Eugeny commented Dec 10, 2018

Haven't considered this! Would preventDefault() here prevent the browser's paste event which you're listening to for pasteHandler though?

@Tyriar
Copy link
Member

Tyriar commented Dec 10, 2018

@Eugeny I think so, in vscode I believe only "vscode keybindings" can trigger pastes and they end up firing this to do the actual paste:

https://github.com/Microsoft/vscode/blob/0d375bf5fc3b34144fde240626603c7f0b2cfc55/src/vs/workbench/parts/terminal/electron-browser/terminalInstance.ts#L631-L634

@Eugeny
Copy link
Member Author

Eugeny commented Jan 16, 2019

Can confirm this works.

@Eugeny Eugeny closed this as completed Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info type/enhancement Features or improvements to existing features
Projects
None yet
Development

No branches or pull requests

2 participants