fix some element types reset to selection when the lock is active (#746)
* keep arrows and lines selected if locked * keep element type selected if locked after inserting text * ensure clicking outside doesn't create new text * esc should switch to selection even if locked * reset cursor when creating text via doubleClick Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
parent
1ec3946ed6
commit
fa12125db0
@ -2,6 +2,7 @@ import { Action } from "./types";
|
|||||||
import { KEYS } from "../keys";
|
import { KEYS } from "../keys";
|
||||||
import { clearSelection } from "../scene";
|
import { clearSelection } from "../scene";
|
||||||
import { isInvisiblySmallElement } from "../element";
|
import { isInvisiblySmallElement } from "../element";
|
||||||
|
import { resetCursor } from "../utils";
|
||||||
|
|
||||||
export const actionFinalize: Action = {
|
export const actionFinalize: Action = {
|
||||||
name: "finalize",
|
name: "finalize",
|
||||||
@ -20,11 +21,17 @@ export const actionFinalize: Action = {
|
|||||||
}
|
}
|
||||||
appState.multiElement.shape = null;
|
appState.multiElement.shape = null;
|
||||||
}
|
}
|
||||||
|
if (!appState.elementLocked || !appState.multiElement) {
|
||||||
|
resetCursor();
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
elements: newElements,
|
elements: newElements,
|
||||||
appState: {
|
appState: {
|
||||||
...appState,
|
...appState,
|
||||||
elementType: "selection",
|
elementType:
|
||||||
|
appState.elementLocked && appState.multiElement
|
||||||
|
? appState.elementType
|
||||||
|
: "selection",
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
multiElement: null,
|
multiElement: null,
|
||||||
},
|
},
|
||||||
|
@ -48,6 +48,7 @@ import {
|
|||||||
capitalizeString,
|
capitalizeString,
|
||||||
distance,
|
distance,
|
||||||
distance2d,
|
distance2d,
|
||||||
|
resetCursor,
|
||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { KEYS, isArrowKey } from "./keys";
|
import { KEYS, isArrowKey } from "./keys";
|
||||||
|
|
||||||
@ -102,10 +103,6 @@ import { copyToAppClipboard, getClipboardContent } from "./clipboard";
|
|||||||
let { elements } = createScene();
|
let { elements } = createScene();
|
||||||
const { history } = createHistory();
|
const { history } = createHistory();
|
||||||
|
|
||||||
function resetCursor() {
|
|
||||||
document.documentElement.style.cursor = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function setCursorForShape(shape: string) {
|
function setCursorForShape(shape: string) {
|
||||||
if (shape === "selection") {
|
if (shape === "selection") {
|
||||||
resetCursor();
|
resetCursor();
|
||||||
@ -1014,6 +1011,12 @@ export class App extends React.Component<any, AppState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isTextElement(element)) {
|
if (isTextElement(element)) {
|
||||||
|
// if we're currently still editing text, clicking outside
|
||||||
|
// should only finalize it, not create another (irrespective
|
||||||
|
// of state.elementLocked)
|
||||||
|
if (this.state.editingElement?.type === "text") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let textX = e.clientX;
|
let textX = e.clientX;
|
||||||
let textY = e.clientY;
|
let textY = e.clientY;
|
||||||
if (!e.altKey) {
|
if (!e.altKey) {
|
||||||
@ -1033,7 +1036,6 @@ export class App extends React.Component<any, AppState> {
|
|||||||
this.setState({
|
this.setState({
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
editingElement: null,
|
editingElement: null,
|
||||||
elementType: "selection",
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1058,6 +1060,9 @@ export class App extends React.Component<any, AppState> {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
if (this.state.elementLocked) {
|
||||||
|
setCursorForShape(this.state.elementType);
|
||||||
|
}
|
||||||
history.resumeRecording();
|
history.resumeRecording();
|
||||||
resetSelection();
|
resetSelection();
|
||||||
},
|
},
|
||||||
@ -1065,10 +1070,17 @@ export class App extends React.Component<any, AppState> {
|
|||||||
resetSelection();
|
resetSelection();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
resetCursor();
|
||||||
|
if (!this.state.elementLocked) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
editingElement: element,
|
||||||
elementType: "selection",
|
elementType: "selection",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
editingElement: element,
|
editingElement: element,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else if (
|
} else if (
|
||||||
this.state.elementType === "arrow" ||
|
this.state.elementType === "arrow" ||
|
||||||
@ -1563,10 +1575,17 @@ export class App extends React.Component<any, AppState> {
|
|||||||
this.setState({ multiElement: this.state.draggingElement });
|
this.setState({ multiElement: this.state.draggingElement });
|
||||||
} else if (draggingOccurred && !multiElement) {
|
} else if (draggingOccurred && !multiElement) {
|
||||||
this.state.draggingElement!.isSelected = true;
|
this.state.draggingElement!.isSelected = true;
|
||||||
|
if (!elementLocked) {
|
||||||
|
resetCursor();
|
||||||
this.setState({
|
this.setState({
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
elementType: "selection",
|
elementType: "selection",
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
draggingElement: null,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1660,6 +1679,8 @@ export class App extends React.Component<any, AppState> {
|
|||||||
window.addEventListener("mouseup", onMouseUp);
|
window.addEventListener("mouseup", onMouseUp);
|
||||||
}}
|
}}
|
||||||
onDoubleClick={e => {
|
onDoubleClick={e => {
|
||||||
|
resetCursor();
|
||||||
|
|
||||||
const { x, y } = viewportCoordsToSceneCoords(e, this.state);
|
const { x, y } = viewportCoordsToSceneCoords(e, this.state);
|
||||||
|
|
||||||
const elementAtPosition = getElementAtPosition(elements, x, y);
|
const elementAtPosition = getElementAtPosition(elements, x, y);
|
||||||
@ -1724,7 +1745,6 @@ export class App extends React.Component<any, AppState> {
|
|||||||
this.setState({
|
this.setState({
|
||||||
draggingElement: null,
|
draggingElement: null,
|
||||||
editingElement: null,
|
editingElement: null,
|
||||||
elementType: "selection",
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,3 +126,7 @@ export function distance2d(x1: number, y1: number, x2: number, y2: number) {
|
|||||||
const yd = y2 - y1;
|
const yd = y2 - y1;
|
||||||
return Math.sqrt(xd * xd + yd * yd);
|
return Math.sqrt(xd * xd + yd * yd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resetCursor() {
|
||||||
|
document.documentElement.style.cursor = "";
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user