mirror of
				https://github.com/excalidraw/excalidraw.git
				synced 2025-11-04 12:54:23 +01:00 
			
		
		
		
	add laser pointer to view mode
This commit is contained in:
		@@ -46,6 +46,7 @@ import {
 | 
			
		||||
  getDefaultAppState,
 | 
			
		||||
  isEraserActive,
 | 
			
		||||
  isHandToolActive,
 | 
			
		||||
  isLaserPointerActive,
 | 
			
		||||
} from "../appState";
 | 
			
		||||
import { parseClipboard } from "../clipboard";
 | 
			
		||||
import {
 | 
			
		||||
@@ -343,7 +344,11 @@ import {
 | 
			
		||||
  actionRemoveAllElementsFromFrame,
 | 
			
		||||
  actionSelectAllElementsInFrame,
 | 
			
		||||
} from "../actions/actionFrame";
 | 
			
		||||
import { actionToggleHandTool, zoomToFit } from "../actions/actionCanvas";
 | 
			
		||||
import {
 | 
			
		||||
  actionToggleHandTool,
 | 
			
		||||
  zoomToFit,
 | 
			
		||||
  actionToggleLaserPointer,
 | 
			
		||||
} from "../actions/actionCanvas";
 | 
			
		||||
import { jotaiStore } from "../jotai";
 | 
			
		||||
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
 | 
			
		||||
import {
 | 
			
		||||
@@ -2910,7 +2915,22 @@ class App extends React.Component<AppProps, AppState> {
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (event.key === KEYS.K && !event.altKey && !event[KEYS.CTRL_OR_CMD]) {
 | 
			
		||||
        if (isLaserPointerActive(this.state)) {
 | 
			
		||||
          this.setActiveTool({
 | 
			
		||||
            type: this.state.viewModeEnabled ? "hand" : "selection",
 | 
			
		||||
          });
 | 
			
		||||
        } else {
 | 
			
		||||
          this.setActiveTool({ type: "laser" });
 | 
			
		||||
        }
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (this.state.viewModeEnabled) {
 | 
			
		||||
        //revert to hand in case a key is pressed (K is handled above)
 | 
			
		||||
        if (event.key !== KEYS.K) {
 | 
			
		||||
          this.setActiveTool({ type: "hand" });
 | 
			
		||||
        }
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@@ -3060,15 +3080,6 @@ class App extends React.Component<AppProps, AppState> {
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (event.key === KEYS.K && !event.altKey && !event[KEYS.CTRL_OR_CMD]) {
 | 
			
		||||
        if (this.state.activeTool.type === "laser") {
 | 
			
		||||
          this.setActiveTool({ type: "selection" });
 | 
			
		||||
        } else {
 | 
			
		||||
          this.setActiveTool({ type: "laser" });
 | 
			
		||||
        }
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (
 | 
			
		||||
        event[KEYS.CTRL_OR_CMD] &&
 | 
			
		||||
        (event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE)
 | 
			
		||||
@@ -4609,7 +4620,7 @@ class App extends React.Component<AppProps, AppState> {
 | 
			
		||||
 | 
			
		||||
    lastPointerUp = onPointerUp;
 | 
			
		||||
 | 
			
		||||
    if (!this.state.viewModeEnabled || this.state.activeTool.type === "laser") {
 | 
			
		||||
    if (this.state.activeTool.type === "laser") {
 | 
			
		||||
      window.addEventListener(EVENT.POINTER_MOVE, onPointerMove);
 | 
			
		||||
      window.addEventListener(EVENT.POINTER_UP, onPointerUp);
 | 
			
		||||
      window.addEventListener(EVENT.KEYDOWN, onKeyDown);
 | 
			
		||||
@@ -4739,7 +4750,7 @@ class App extends React.Component<AppProps, AppState> {
 | 
			
		||||
        (event.button === POINTER_BUTTON.WHEEL ||
 | 
			
		||||
          (event.button === POINTER_BUTTON.MAIN && isHoldingSpace) ||
 | 
			
		||||
          isHandToolActive(this.state) ||
 | 
			
		||||
          this.state.viewModeEnabled)
 | 
			
		||||
          (this.state.viewModeEnabled && !isLaserPointerActive(this.state)))
 | 
			
		||||
      ) ||
 | 
			
		||||
      isTextElement(this.state.editingElement)
 | 
			
		||||
    ) {
 | 
			
		||||
@@ -8143,6 +8154,7 @@ class App extends React.Component<AppProps, AppState> {
 | 
			
		||||
          actionToggleZenMode,
 | 
			
		||||
          actionToggleViewMode,
 | 
			
		||||
          actionToggleStats,
 | 
			
		||||
          actionToggleLaserPointer,
 | 
			
		||||
        ];
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user