add laser pointer to view mode
This commit is contained in:
parent
a249f332a2
commit
ca22a52102
@ -18,6 +18,7 @@ import {
|
|||||||
getDefaultAppState,
|
getDefaultAppState,
|
||||||
isEraserActive,
|
isEraserActive,
|
||||||
isHandToolActive,
|
isHandToolActive,
|
||||||
|
isLaserPointerActive,
|
||||||
} from "../appState";
|
} from "../appState";
|
||||||
import { DEFAULT_CANVAS_BACKGROUND_PICKS } from "../colors";
|
import { DEFAULT_CANVAS_BACKGROUND_PICKS } from "../colors";
|
||||||
import { Bounds } from "../element/bounds";
|
import { Bounds } from "../element/bounds";
|
||||||
@ -439,3 +440,46 @@ export const actionToggleHandTool = register({
|
|||||||
},
|
},
|
||||||
keyTest: (event) => event.key === KEYS.H,
|
keyTest: (event) => event.key === KEYS.H,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const actionToggleLaserPointer = register({
|
||||||
|
name: "toggleLaserPointerTool",
|
||||||
|
viewMode: true,
|
||||||
|
trackEvent: { category: "menu" },
|
||||||
|
perform(elements, appState, _, app) {
|
||||||
|
let activeTool: AppState["activeTool"];
|
||||||
|
|
||||||
|
if (isLaserPointerActive(appState)) {
|
||||||
|
activeTool = updateActiveTool(appState, {
|
||||||
|
...(appState.activeTool.lastActiveTool || {
|
||||||
|
type: appState.viewModeEnabled ? "hand" : "selection",
|
||||||
|
}),
|
||||||
|
lastActiveToolBeforeEraser: null,
|
||||||
|
});
|
||||||
|
setCursor(
|
||||||
|
app.interactiveCanvas,
|
||||||
|
appState.viewModeEnabled ? CURSOR_TYPE.GRAB : CURSOR_TYPE.POINTER,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
activeTool = updateActiveTool(appState, {
|
||||||
|
type: "laser",
|
||||||
|
lastActiveToolBeforeEraser: appState.activeTool,
|
||||||
|
});
|
||||||
|
setCursor(app.interactiveCanvas, CURSOR_TYPE.CROSSHAIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
appState: {
|
||||||
|
...appState,
|
||||||
|
selectedElementIds: {},
|
||||||
|
selectedGroupIds: {},
|
||||||
|
activeEmbeddable: null,
|
||||||
|
activeTool,
|
||||||
|
},
|
||||||
|
commitToHistory: true,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
checked: (appState) => appState.activeTool.type === "laser",
|
||||||
|
contextItemLabel: "labels.laser",
|
||||||
|
keyTest: (event) =>
|
||||||
|
event.code === CODES.K && !event[KEYS.CTRL_OR_CMD] && !event.altKey,
|
||||||
|
});
|
||||||
|
@ -124,7 +124,8 @@ export type ActionName =
|
|||||||
| "setFrameAsActiveTool"
|
| "setFrameAsActiveTool"
|
||||||
| "setEmbeddableAsActiveTool"
|
| "setEmbeddableAsActiveTool"
|
||||||
| "createContainerFromText"
|
| "createContainerFromText"
|
||||||
| "wrapTextInContainer";
|
| "wrapTextInContainer"
|
||||||
|
| "toggleLaserPointerTool";
|
||||||
|
|
||||||
export type PanelComponentProps = {
|
export type PanelComponentProps = {
|
||||||
elements: readonly ExcalidrawElement[];
|
elements: readonly ExcalidrawElement[];
|
||||||
|
@ -266,3 +266,11 @@ export const isHandToolActive = ({
|
|||||||
}) => {
|
}) => {
|
||||||
return activeTool.type === "hand";
|
return activeTool.type === "hand";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isLaserPointerActive = ({
|
||||||
|
activeTool,
|
||||||
|
}: {
|
||||||
|
activeTool: AppState["activeTool"];
|
||||||
|
}) => {
|
||||||
|
return activeTool.type === "laser";
|
||||||
|
};
|
||||||
|
@ -46,6 +46,7 @@ import {
|
|||||||
getDefaultAppState,
|
getDefaultAppState,
|
||||||
isEraserActive,
|
isEraserActive,
|
||||||
isHandToolActive,
|
isHandToolActive,
|
||||||
|
isLaserPointerActive,
|
||||||
} from "../appState";
|
} from "../appState";
|
||||||
import { parseClipboard } from "../clipboard";
|
import { parseClipboard } from "../clipboard";
|
||||||
import {
|
import {
|
||||||
@ -343,7 +344,11 @@ import {
|
|||||||
actionRemoveAllElementsFromFrame,
|
actionRemoveAllElementsFromFrame,
|
||||||
actionSelectAllElementsInFrame,
|
actionSelectAllElementsInFrame,
|
||||||
} from "../actions/actionFrame";
|
} from "../actions/actionFrame";
|
||||||
import { actionToggleHandTool, zoomToFit } from "../actions/actionCanvas";
|
import {
|
||||||
|
actionToggleHandTool,
|
||||||
|
zoomToFit,
|
||||||
|
actionToggleLaserPointer,
|
||||||
|
} from "../actions/actionCanvas";
|
||||||
import { jotaiStore } from "../jotai";
|
import { jotaiStore } from "../jotai";
|
||||||
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
|
import { activeConfirmDialogAtom } from "./ActiveConfirmDialog";
|
||||||
import {
|
import {
|
||||||
@ -2910,7 +2915,22 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
return;
|
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) {
|
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;
|
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 (
|
if (
|
||||||
event[KEYS.CTRL_OR_CMD] &&
|
event[KEYS.CTRL_OR_CMD] &&
|
||||||
(event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE)
|
(event.key === KEYS.BACKSPACE || event.key === KEYS.DELETE)
|
||||||
@ -4609,7 +4620,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
|
|
||||||
lastPointerUp = onPointerUp;
|
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_MOVE, onPointerMove);
|
||||||
window.addEventListener(EVENT.POINTER_UP, onPointerUp);
|
window.addEventListener(EVENT.POINTER_UP, onPointerUp);
|
||||||
window.addEventListener(EVENT.KEYDOWN, onKeyDown);
|
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.WHEEL ||
|
||||||
(event.button === POINTER_BUTTON.MAIN && isHoldingSpace) ||
|
(event.button === POINTER_BUTTON.MAIN && isHoldingSpace) ||
|
||||||
isHandToolActive(this.state) ||
|
isHandToolActive(this.state) ||
|
||||||
this.state.viewModeEnabled)
|
(this.state.viewModeEnabled && !isLaserPointerActive(this.state)))
|
||||||
) ||
|
) ||
|
||||||
isTextElement(this.state.editingElement)
|
isTextElement(this.state.editingElement)
|
||||||
) {
|
) {
|
||||||
@ -8143,6 +8154,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||||||
actionToggleZenMode,
|
actionToggleZenMode,
|
||||||
actionToggleViewMode,
|
actionToggleViewMode,
|
||||||
actionToggleStats,
|
actionToggleStats,
|
||||||
|
actionToggleLaserPointer,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ export const CODES = {
|
|||||||
Z: "KeyZ",
|
Z: "KeyZ",
|
||||||
R: "KeyR",
|
R: "KeyR",
|
||||||
S: "KeyS",
|
S: "KeyS",
|
||||||
|
K: "KeyK",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const KEYS = {
|
export const KEYS = {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"labels": {
|
"labels": {
|
||||||
|
"laser": "Toggle laser pointer",
|
||||||
"paste": "Paste",
|
"paste": "Paste",
|
||||||
"pasteAsPlaintext": "Paste as plaintext",
|
"pasteAsPlaintext": "Paste as plaintext",
|
||||||
"pasteCharts": "Paste charts",
|
"pasteCharts": "Paste charts",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user