* Bind certain mouse events to the terminal. * By default only 3 button + wheel up/down is ativated. For higher buttons * no mouse report will be created. Typically the standard actions will be active. * * There are several reasons not to enable support for higher buttons/wheel: * - B
()
| 600 | * TODO: Move mouse event code into its own file. |
| 601 | */ |
| 602 | public bindMouse(): void { |
| 603 | const self = this; |
| 604 | const el = this.element!; |
| 605 | |
| 606 | // send event to CoreMouseService |
| 607 | function sendEvent(ev: MouseEvent | WheelEvent): boolean { |
| 608 | // get mouse coordinates |
| 609 | const pos = self._mouseService!.getMouseReportCoords(ev, self.screenElement!); |
| 610 | if (!pos) { |
| 611 | return false; |
| 612 | } |
| 613 | |
| 614 | let but: CoreMouseButton; |
| 615 | let action: CoreMouseAction | undefined; |
| 616 | switch ((ev as any).overrideType || ev.type) { |
| 617 | case 'mousemove': |
| 618 | action = CoreMouseAction.MOVE; |
| 619 | if (ev.buttons === undefined) { |
| 620 | // buttons is not supported on macOS, try to get a value from button instead |
| 621 | but = CoreMouseButton.NONE; |
| 622 | if (ev.button !== undefined) { |
| 623 | but = ev.button < 3 ? ev.button : CoreMouseButton.NONE; |
| 624 | } |
| 625 | } else { |
| 626 | // according to MDN buttons only reports up to button 5 (AUX2) |
| 627 | but = ev.buttons & 1 ? CoreMouseButton.LEFT : |
| 628 | ev.buttons & 4 ? CoreMouseButton.MIDDLE : |
| 629 | ev.buttons & 2 ? CoreMouseButton.RIGHT : |
| 630 | CoreMouseButton.NONE; // fallback to NONE |
| 631 | } |
| 632 | break; |
| 633 | case 'mouseup': |
| 634 | action = CoreMouseAction.UP; |
| 635 | but = ev.button < 3 ? ev.button : CoreMouseButton.NONE; |
| 636 | break; |
| 637 | case 'mousedown': |
| 638 | action = CoreMouseAction.DOWN; |
| 639 | but = ev.button < 3 ? ev.button : CoreMouseButton.NONE; |
| 640 | break; |
| 641 | case 'wheel': |
| 642 | if (self._customWheelEventHandler && self._customWheelEventHandler(ev as WheelEvent) === false) { |
| 643 | return false; |
| 644 | } |
| 645 | const deltaY = (ev as WheelEvent).deltaY; |
| 646 | if (deltaY === 0) { |
| 647 | return false; |
| 648 | } |
| 649 | const lines = self.coreMouseService.consumeWheelEvent( |
| 650 | ev as WheelEvent, |
| 651 | self._renderService?.dimensions?.device?.cell?.height, |
| 652 | self._coreBrowserService?.dpr |
| 653 | ); |
| 654 | if (lines === 0) { |
| 655 | return false; |
| 656 | } |
| 657 | action = deltaY < 0 ? CoreMouseAction.UP : CoreMouseAction.DOWN; |
| 658 | but = CoreMouseButton.WHEEL; |
| 659 | break; |
no test coverage detected