Skip to content

Commit

Permalink
fix(editor): add index checking to selected elements array (#9453)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Sun committed Dec 31, 2024
1 parent 597b631 commit b51de2a
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export class EdgelessLockButton extends SignalWatcher(
private _lock() {
const { service, doc, std } = this.edgeless;

doc.captureSync();

// get most top selected elements(*) from tree, like in a tree below
// G0
// / \
Expand All @@ -46,12 +44,16 @@ export class EdgelessLockButton extends SignalWatcher(
// return [E1]

const selectedElements = this._selectedElements;
if (selectedElements.length === 0) return;

const levels = selectedElements.map(element => element.groups.length);
const topElement = selectedElements[levels.indexOf(Math.min(...levels))];
const otherElements = selectedElements.filter(
element => element !== topElement
);

doc.captureSync();

// release other elements from their groups and group with top element
otherElements.forEach(element => {
// oxlint-disable-next-line unicorn/prefer-dom-node-remove
Expand Down Expand Up @@ -97,9 +99,13 @@ export class EdgelessLockButton extends SignalWatcher(

private _unlock() {
const { service, doc } = this.edgeless;

const selectedElements = this._selectedElements;
if (selectedElements.length === 0) return;

doc.captureSync();

this._selectedElements.forEach(element => {
selectedElements.forEach(element => {
if (element instanceof GroupElementModel) {
service.ungroup(element);
} else {
Expand Down

0 comments on commit b51de2a

Please sign in to comment.