| 124 | } |
| 125 | |
| 126 | class TouchSelectionMenuController { |
| 127 | #view; |
| 128 | #container; |
| 129 | #getActiveFile; |
| 130 | #isShiftSelectionActive; |
| 131 | #stateSyncRaf = 0; |
| 132 | #isScrolling = false; |
| 133 | #isPointerInteracting = false; |
| 134 | #shiftSelectionSession = null; |
| 135 | #pendingShiftSelectionClick = null; |
| 136 | #menuActive = false; |
| 137 | #menuRequested = false; |
| 138 | #enabled = true; |
| 139 | #handlingMenuAction = false; |
| 140 | #menuShowTimer = null; |
| 141 | #tooltipObserver = null; |
| 142 | |
| 143 | constructor(view, options = {}) { |
| 144 | this.#view = view; |
| 145 | this.#container = |
| 146 | options.container || view.dom.closest(".editor-container") || view.dom; |
| 147 | this.#getActiveFile = options.getActiveFile || (() => null); |
| 148 | this.#isShiftSelectionActive = |
| 149 | options.isShiftSelectionActive || (() => false); |
| 150 | this.$menu = document.createElement("menu"); |
| 151 | this.$menu.className = "cursor-menu"; |
| 152 | this.#bindEvents(); |
| 153 | } |
| 154 | |
| 155 | #bindEvents() { |
| 156 | const root = this.#view.dom; |
| 157 | root.addEventListener("contextmenu", this.#onContextMenu, true); |
| 158 | document.addEventListener("pointerdown", this.#onGlobalPointerDown, true); |
| 159 | document.addEventListener("pointerup", this.#onGlobalPointerUp, true); |
| 160 | document.addEventListener("pointercancel", this.#onGlobalPointerUp, true); |
| 161 | |
| 162 | this.#tooltipObserver = new MutationObserver((mutations) => { |
| 163 | const relevant = mutations.some((m) => |
| 164 | [...m.addedNodes, ...m.removedNodes].some( |
| 165 | (n) => |
| 166 | n.nodeType === 1 && |
| 167 | (n.matches?.(".cm-tooltip") || n.querySelector?.(".cm-tooltip")), |
| 168 | ), |
| 169 | ); |
| 170 | if (!relevant || !this.#menuActive || !this.#shouldShowMenu()) { |
| 171 | return; |
| 172 | } |
| 173 | this.#showMenuDeferred(); |
| 174 | }); |
| 175 | this.#tooltipObserver.observe(this.#view.dom, { |
| 176 | childList: true, |
| 177 | subtree: true, |
| 178 | }); |
| 179 | } |
| 180 | |
| 181 | destroy() { |
| 182 | const root = this.#view.dom; |
| 183 | root.removeEventListener("contextmenu", this.#onContextMenu, true); |
nothing calls this directly
no test coverage detected