MCPcopy Create free account
hub / github.com/handsontable/handsontable / registerEvents

Method registerEvents

handsontable/src/tableView.ts:332–514  ·  view source on GitHub ↗

* Attaches necessary listeners. * * @private

()

Source from the content-addressed store, hash-verified

330 * @private
331 */
332 registerEvents() {
333 const { rootWrapperElement, rootElement, rootDocument, selection, rootWindow } = this.hot;
334 const documentElement = rootDocument.documentElement;
335
336 this.eventManager.addEventListener(rootElement, 'mousedown', (event) => {
337 // Ignore synthetic mousedown events from Android touch interactions.
338 if (this.#isSyntheticMouseEvent(event)) {
339 return;
340 }
341
342 // Leave the middle mouse button (the scroll wheel) untouched so the browser can start its
343 // native autoscroll. Calling `preventDefault()` on a middle-button mousedown cancels that
344 // panning behavior, which is available on Windows and Linux (https://github.com/handsontable/handsontable/issues/2722).
345 if (isMiddleClick(event)) {
346 return;
347 }
348
349 this.#selectionMouseDown = true;
350
351 if (!this.isTextSelectionAllowed(eventTargetEl(event)!)) {
352 clearTextSelection(rootWindow);
353 event.preventDefault();
354 rootWindow.focus(); // make sure that window that contains HOT is active. Important when HOT is in iframe.
355 }
356 });
357
358 this.eventManager.addEventListener(rootElement, 'mouseup', (event) => {
359 // Ignore synthetic mouseup events from Android touch interactions.
360 if (this.#isSyntheticMouseEvent(event)) {
361 return;
362 }
363
364 this.#selectionMouseDown = false;
365 });
366 this.eventManager.addEventListener(rootElement, 'mousemove', (event) => {
367 if (this.#selectionMouseDown && !this.isTextSelectionAllowed(eventTargetEl(event)!)) {
368 // Clear selection only when fragmentSelection is enabled, otherwise clearing selection breaks the IME editor.
369 if (this.settings.fragmentSelection) {
370 clearTextSelection(rootWindow);
371 }
372 event.preventDefault();
373 }
374 });
375
376 this.eventManager.addEventListener(documentElement, 'keyup', (event) => {
377 // TODO: is it the best place and way to finish cell selection?
378 if (selection.isInProgress() && !(event as KeyboardEvent).shiftKey) {
379 selection.finish();
380 }
381 });
382
383 this.eventManager.addEventListener(documentElement, 'mouseup', (event) => {
384 if (selection.isInProgress() && isLeftClick(event)) {
385 selection.finish();
386 }
387
388 this.#mouseDown = false;
389

Callers 1

constructorMethod · 0.95

Calls 15

isMiddleClickFunction · 0.90
eventTargetElFunction · 0.90
clearTextSelectionFunction · 0.90
isLeftClickFunction · 0.90
isOutsideInputFunction · 0.90
isInputFunction · 0.90
isRightClickFunction · 0.90
getScrollbarWidthFunction · 0.90
getParentWindowFunction · 0.90
addEventListenerMethod · 0.80

Tested by

no test coverage detected