mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-04 08:38:34 +00:00
fix(editor): add index checking to selected elements array (#9453)
Close https://toeverything.sentry.io/issues/6187666983/?alert_rule_id=15031714&alert_type=issue¬ification_uuid=fe3f4b9d-1e86-420e-a715-c3ca0fa932e4&project=4506307500179456&referrer=slack
This commit is contained in:
@@ -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
|
||||
// / \
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user