Skip to content

Commit

Permalink
fix(sheet): first sheet hidden (#1538)
Browse files Browse the repository at this point in the history
* fix(sheet): first sheet hidden

* docs(sheet): add comment
  • Loading branch information
DR-Univer committed Mar 11, 2024
1 parent e0b49cc commit 6123772
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/core/src/sheets/workbook.ts
Expand Up @@ -204,13 +204,25 @@ export class Workbook extends Disposable {
*/
getActiveSheet(): Worksheet {
const currentActive = this.getRawActiveSheet();
if (!currentActive) {
const worksheet = this._worksheets.get(this._snapshot.sheetOrder[0])!;
this.setActiveSheet(worksheet);
return worksheet;
if (currentActive) {
return currentActive;
}

return currentActive;
/**
* If the first sheet is hidden, we should set the first unhidden sheet to be active.
*/
const sheetOrder = this._snapshot.sheetOrder;
for (let i = 0, len = sheetOrder.length; i < len; i++) {
const worksheet = this._worksheets.get(sheetOrder[i]);
if (worksheet && worksheet.isSheetHidden() !== BooleanNumber.TRUE) {
this.setActiveSheet(worksheet);
return worksheet;
}
}

const worksheet = this._worksheets.get(sheetOrder[0])!;
this.setActiveSheet(worksheet);
return worksheet;
}

setActiveSheet(worksheet: Nullable<Worksheet>): void {
Expand Down

0 comments on commit 6123772

Please sign in to comment.