Compare commits
4 Commits
master
...
zsviczian-
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4c5e196f25 | ||
![]() |
25af9023d4 | ||
![]() |
76795c7d1b | ||
![]() |
ca22a52102 |
@ -18,6 +18,7 @@ import {
|
||||
getDefaultAppState,
|
||||
isEraserActive,
|
||||
isHandToolActive,
|
||||
isLaserPointerActive,
|
||||
} from "../appState";
|
||||
import { DEFAULT_CANVAS_BACKGROUND_PICKS } from "../colors";
|
||||
import { Bounds } from "../element/bounds";
|
||||
@ -439,3 +440,44 @@ export const actionToggleHandTool = register({
|
||||
},
|
||||
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",
|
||||
});
|
||||
|
@ -36,6 +36,7 @@ export type ShortcutName =
|
||||
| "flipVertical"
|
||||
| "hyperlink"
|
||||
| "toggleElementLock"
|
||||
| "toggleLaserPointerTool"
|
||||
>
|
||||
| "saveScene"
|
||||
| "imageExport";
|
||||
@ -83,6 +84,7 @@ const shortcutMap: Record<ShortcutName, string[]> = {
|
||||
viewMode: [getShortcutKey("Alt+R")],
|
||||
hyperlink: [getShortcutKey("CtrlOrCmd+K")],
|
||||
toggleElementLock: [getShortcutKey("CtrlOrCmd+Shift+L")],
|
||||
toggleLaserPointerTool: [getShortcutKey("K")],
|
||||
};
|
||||
|
||||
export const getShortcutFromShortcutName = (name: ShortcutName) => {
|
||||
|
@ -124,7 +124,8 @@ export type ActionName =
|
||||
| "setFrameAsActiveTool"
|
||||
| "setEmbeddableAsActiveTool"
|
||||
| "createContainerFromText"
|
||||
| "wrapTextInContainer";
|
||||
| "wrapTextInContainer"
|
||||
| "toggleLaserPointerTool";
|
||||
|
||||
export type PanelComponentProps = {
|
||||
elements: readonly ExcalidrawElement[];
|
||||
|
@ -266,3 +266,11 @@ export const isHandToolActive = ({
|
||||
}) => {
|
||||
return activeTool.type === "hand";
|
||||
};
|
||||
|
||||
export const isLaserPointerActive = ({
|
||||
activeTool,
|
||||
}: {
|
||||
activeTool: AppState["activeTool"];
|
||||
}) => {
|
||||
return activeTool.type === "laser";
|
||||
};
|
||||
|
@ -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: "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: "selection" });
|
||||
}
|
||||
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)
|
||||
@ -3612,6 +3623,18 @@ class App extends React.Component<AppProps, AppState> {
|
||||
if (this.state.multiElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.state.viewModeEnabled) {
|
||||
if (this.state.activeTool.type === "laser") {
|
||||
this.setActiveTool({ type: "selection" });
|
||||
setCursor(this.interactiveCanvas, CURSOR_TYPE.GRAB);
|
||||
} else {
|
||||
this.setActiveTool({ type: "laser" });
|
||||
setCursor(this.interactiveCanvas, CURSOR_TYPE.CROSSHAIR);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// we should only be able to double click when mode is selection
|
||||
if (this.state.activeTool.type !== "selection") {
|
||||
return;
|
||||
@ -4739,7 +4762,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 +8166,7 @@ class App extends React.Component<AppProps, AppState> {
|
||||
actionToggleZenMode,
|
||||
actionToggleViewMode,
|
||||
actionToggleStats,
|
||||
actionToggleLaserPointer,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -155,9 +155,7 @@ const InteractiveCanvas = (props: InteractiveCanvasProps) => {
|
||||
onPointerCancel={props.onPointerCancel}
|
||||
onTouchMove={props.onTouchMove}
|
||||
onPointerDown={props.onPointerDown}
|
||||
onDoubleClick={
|
||||
props.appState.viewModeEnabled ? undefined : props.onDoubleClick
|
||||
}
|
||||
onDoubleClick={props.onDoubleClick}
|
||||
>
|
||||
{t("labels.drawingCanvas")}
|
||||
</canvas>
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"labels": {
|
||||
"laser": "Toggle laser pointer",
|
||||
"paste": "Paste",
|
||||
"pasteAsPlaintext": "Paste as plaintext",
|
||||
"pasteCharts": "Paste charts",
|
||||
|
Loading…
x
Reference in New Issue
Block a user