Compare commits

...

4 Commits

Author SHA1 Message Date
Ryan Di
0bf1b4c4af (un)lock a frame should not affect elements unrelated to the frame 2023-11-22 18:35:05 +08:00
Ryan Di
d9d1a3ab99 improve cursor style when frame's locked 2023-11-22 18:28:57 +08:00
Ryan Di
c43d9d44f0 update test snapshot 2023-11-22 18:20:31 +08:00
Ryan Di
c9af72e2ee fix: lock/unlock elements in frames 2023-11-08 15:48:36 +08:00
3 changed files with 12 additions and 14 deletions

View File

@ -10,17 +10,12 @@ const shouldLock = (elements: readonly ExcalidrawElement[]) =>
export const actionToggleElementLock = register({ export const actionToggleElementLock = register({
name: "toggleElementLock", name: "toggleElementLock",
trackEvent: { category: "element" }, trackEvent: { category: "element" },
predicate: (elements, appState, _, app) => {
const selectedElements = app.scene.getSelectedElements(appState);
return !selectedElements.some(
(element) => element.locked && element.frameId,
);
},
perform: (elements, appState, _, app) => { perform: (elements, appState, _, app) => {
// Frames and their children should not be selected at the same time.
// Therefore, there's no need to include elements in frame in the selection.
const selectedElements = app.scene.getSelectedElements({ const selectedElements = app.scene.getSelectedElements({
selectedElementIds: appState.selectedElementIds, selectedElementIds: appState.selectedElementIds,
includeBoundTextElement: true, includeBoundTextElement: true,
includeElementsInFrames: true,
}); });
if (!selectedElements.length) { if (!selectedElements.length) {
@ -31,7 +26,12 @@ export const actionToggleElementLock = register({
const selectedElementsMap = arrayToMap(selectedElements); const selectedElementsMap = arrayToMap(selectedElements);
return { return {
elements: elements.map((element) => { elements: elements.map((element) => {
if (!selectedElementsMap.has(element.id)) { if (
!selectedElementsMap.has(element.id) &&
(!element.frameId ||
// lock frame children if frame is selected
(element.frameId && !selectedElementsMap.has(element.frameId)))
) {
return element; return element;
} }

View File

@ -1137,7 +1137,10 @@ class App extends React.Component<AppProps, AppState> {
overflow: f.id === this.state.editingFrame ? "visible" : "hidden", overflow: f.id === this.state.editingFrame ? "visible" : "hidden",
whiteSpace: "nowrap", whiteSpace: "nowrap",
textOverflow: "ellipsis", textOverflow: "ellipsis",
cursor: CURSOR_TYPE.MOVE, cursor:
!f.locked && this.state.activeTool.type === "selection"
? CURSOR_TYPE.MOVE
: this.interactiveCanvas?.style.cursor,
pointerEvents: this.state.viewModeEnabled pointerEvents: this.state.viewModeEnabled
? POINTER_EVENTS.disabled ? POINTER_EVENTS.disabled
: POINTER_EVENTS.enabled, : POINTER_EVENTS.enabled,

View File

@ -263,7 +263,6 @@ exports[`contextMenu element > right-clicking on a group should select whole gro
"keyTest": [Function], "keyTest": [Function],
"name": "toggleElementLock", "name": "toggleElementLock",
"perform": [Function], "perform": [Function],
"predicate": [Function],
"trackEvent": { "trackEvent": {
"category": "element", "category": "element",
}, },
@ -4847,7 +4846,6 @@ exports[`contextMenu element > shows 'Group selection' in context menu for multi
"keyTest": [Function], "keyTest": [Function],
"name": "toggleElementLock", "name": "toggleElementLock",
"perform": [Function], "perform": [Function],
"predicate": [Function],
"trackEvent": { "trackEvent": {
"category": "element", "category": "element",
}, },
@ -5427,7 +5425,6 @@ exports[`contextMenu element > shows 'Ungroup selection' in context menu for gro
"keyTest": [Function], "keyTest": [Function],
"name": "toggleElementLock", "name": "toggleElementLock",
"perform": [Function], "perform": [Function],
"predicate": [Function],
"trackEvent": { "trackEvent": {
"category": "element", "category": "element",
}, },
@ -6345,7 +6342,6 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap
"keyTest": [Function], "keyTest": [Function],
"name": "toggleElementLock", "name": "toggleElementLock",
"perform": [Function], "perform": [Function],
"predicate": [Function],
"trackEvent": { "trackEvent": {
"category": "element", "category": "element",
}, },
@ -6719,7 +6715,6 @@ exports[`contextMenu element > shows context menu for element > [end of test] ap
"keyTest": [Function], "keyTest": [Function],
"name": "toggleElementLock", "name": "toggleElementLock",
"perform": [Function], "perform": [Function],
"predicate": [Function],
"trackEvent": { "trackEvent": {
"category": "element", "category": "element",
}, },