MCPcopy
hub / github.com/xtermjs/xterm.js / _initGlobal

Method _initGlobal

src/browser/CoreBrowserTerminal.ts:330–372  ·  view source on GitHub ↗

* Initialize default behavior

()

Source from the content-addressed store, hash-verified

328 * Initialize default behavior
329 */
330 private _initGlobal(): void {
331 this._bindKeys();
332
333 // Bind clipboard functionality
334 this._register(addDisposableListener(this.element!, 'copy', (event: ClipboardEvent) => {
335 // If mouse events are active it means the selection manager is disabled and
336 // copy should be handled by the host program.
337 if (!this.hasSelection()) {
338 return;
339 }
340 copyHandler(event, this._selectionService!);
341 }));
342 const pasteHandlerWrapper = (event: ClipboardEvent): void => handlePasteEvent(event, this.textarea!, this.coreService, this.optionsService);
343 this._register(addDisposableListener(this.textarea!, 'paste', pasteHandlerWrapper));
344 this._register(addDisposableListener(this.element!, 'paste', pasteHandlerWrapper));
345
346 // Handle right click context menus
347 if (Browser.isFirefox) {
348 // Firefox doesn't appear to fire the contextmenu event on right click
349 this._register(addDisposableListener(this.element!, 'mousedown', (event: MouseEvent) => {
350 if (event.button === 2) {
351 rightClickHandler(event, this.textarea!, this.screenElement!, this._selectionService!, this.options.rightClickSelectsWord);
352 }
353 }));
354 } else {
355 this._register(addDisposableListener(this.element!, 'contextmenu', (event: MouseEvent) => {
356 rightClickHandler(event, this.textarea!, this.screenElement!, this._selectionService!, this.options.rightClickSelectsWord);
357 }));
358 }
359
360 // Move the textarea under the cursor when middle clicking on Linux to ensure
361 // middle click to paste selection works. This only appears to work in Chrome
362 // at the time is writing.
363 if (Browser.isLinux) {
364 // Use auxclick event over mousedown the latter doesn't seem to work. Note
365 // that the regular click event doesn't fire for the middle mouse button.
366 this._register(addDisposableListener(this.element!, 'auxclick', (event: MouseEvent) => {
367 if (event.button === 1) {
368 moveTextAreaUnderMouseCursor(event, this.textarea!, this.screenElement!);
369 }
370 }));
371 }
372 }
373
374 /**
375 * Apply key handling to the terminal

Callers 1

openMethod · 0.95

Calls 6

_bindKeysMethod · 0.95
hasSelectionMethod · 0.95
addDisposableListenerFunction · 0.90
copyHandlerFunction · 0.90
rightClickHandlerFunction · 0.90

Tested by

no test coverage detected