Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): add index checking to selected elements array #9453

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading