mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-30 00:29:46 +08:00
fix(core): fix active view undefined (#7161)
This commit is contained in:
@@ -37,6 +37,7 @@ export class Workbench extends Entity {
|
|||||||
);
|
);
|
||||||
|
|
||||||
active(index: number) {
|
active(index: number) {
|
||||||
|
index = Math.max(0, Math.min(index, this.views$.value.length - 1));
|
||||||
this.activeViewIndex$.next(index);
|
this.activeViewIndex$.next(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,9 +123,14 @@ export class Workbench extends Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moveView(from: number, to: number) {
|
moveView(from: number, to: number) {
|
||||||
|
from = Math.max(0, Math.min(from, this.views$.value.length - 1));
|
||||||
|
to = Math.max(0, Math.min(to, this.views$.value.length - 1));
|
||||||
|
if (from === to) return;
|
||||||
const views = [...this.views$.value];
|
const views = [...this.views$.value];
|
||||||
const [removed] = views.splice(from, 1);
|
const fromView = views[from];
|
||||||
views.splice(to, 0, removed);
|
const toView = views[to];
|
||||||
|
views[to] = fromView;
|
||||||
|
views[from] = toView;
|
||||||
this.views$.next(views);
|
this.views$.next(views);
|
||||||
this.active(to);
|
this.active(to);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user