From 09ceb165d515f584b07c8538960d09e9a184f97c Mon Sep 17 00:00:00 2001 From: Univer <68851825+DR-Univer@users.noreply.github.com> Date: Sat, 23 Mar 2024 20:29:36 +0800 Subject: [PATCH] fix(editor): preload the editor (#1662) * fix(editor): preload the editor * fix(editor): zen editor lazy --- .../sheets-formula/src/controllers/prompt.controller.ts | 2 +- .../src/controllers/editor/editing.controller.ts | 2 +- .../src/controllers/editor/end-edit.controller.ts | 3 +-- .../src/controllers/editor/start-edit.controller.ts | 2 +- .../services/editor/formula-editor-manager.service.ts | 6 +++--- .../src/controllers/zen-editor.controller.ts | 9 ++++++++- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/sheets-formula/src/controllers/prompt.controller.ts b/packages/sheets-formula/src/controllers/prompt.controller.ts index 7078fabf163..c6acaf9e590 100644 --- a/packages/sheets-formula/src/controllers/prompt.controller.ts +++ b/packages/sheets-formula/src/controllers/prompt.controller.ts @@ -121,7 +121,7 @@ enum InputPanelState { const sheetEditorUnitIds = [DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY]; -@OnLifecycle(LifecycleStages.Steady, PromptController) +@OnLifecycle(LifecycleStages.Rendered, PromptController) export class PromptController extends Disposable { private _formulaRefColors: string[] = []; diff --git a/packages/sheets-ui/src/controllers/editor/editing.controller.ts b/packages/sheets-ui/src/controllers/editor/editing.controller.ts index c5a78e831ae..1a592dcd1ea 100644 --- a/packages/sheets-ui/src/controllers/editor/editing.controller.ts +++ b/packages/sheets-ui/src/controllers/editor/editing.controller.ts @@ -29,7 +29,7 @@ import { IRenderManagerService } from '@univerjs/engine-render'; import { Inject } from '@wendellhu/redi'; import { takeUntil } from 'rxjs'; -@OnLifecycle(LifecycleStages.Steady, EditingController) +@OnLifecycle(LifecycleStages.Rendered, EditingController) export class EditingController extends RxDisposable { constructor( @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService, diff --git a/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts b/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts index 15ccccf7a35..d32e648c3e1 100644 --- a/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts +++ b/packages/sheets-ui/src/controllers/editor/end-edit.controller.ts @@ -70,8 +70,7 @@ enum CursorChange { StartEditor, CursorChange, } - -@OnLifecycle(LifecycleStages.Steady, EndEditController) +@OnLifecycle(LifecycleStages.Rendered, EndEditController) export class EndEditController extends Disposable { private _cursorChangeObservers: Nullable>; diff --git a/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts b/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts index f663b80b2b0..9f5bffb90b9 100644 --- a/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts +++ b/packages/sheets-ui/src/controllers/editor/start-edit.controller.ts @@ -74,7 +74,7 @@ interface ICanvasOffset { top: number; } -@OnLifecycle(LifecycleStages.Steady, StartEditController) +@OnLifecycle(LifecycleStages.Rendered, StartEditController) export class StartEditController extends Disposable { private _editorVisiblePrevious = false; diff --git a/packages/sheets-ui/src/services/editor/formula-editor-manager.service.ts b/packages/sheets-ui/src/services/editor/formula-editor-manager.service.ts index e5ba23a92b1..bfa7df55865 100644 --- a/packages/sheets-ui/src/services/editor/formula-editor-manager.service.ts +++ b/packages/sheets-ui/src/services/editor/formula-editor-manager.service.ts @@ -18,7 +18,7 @@ import type { Nullable } from '@univerjs/core'; import type { IDisposable } from '@wendellhu/redi'; import { createIdentifier } from '@wendellhu/redi'; import type { Observable } from 'rxjs'; -import { BehaviorSubject } from 'rxjs'; +import { BehaviorSubject, Subject } from 'rxjs'; export interface IFormulaEditorManagerService { position$: Observable>; @@ -42,10 +42,10 @@ export class FormulaEditorManagerService implements IDisposable { private readonly _focus$ = new BehaviorSubject(this._focus); readonly focus$ = this._focus$.asObservable(); - private readonly _fxBtnClick$ = new BehaviorSubject(false); + private readonly _fxBtnClick$ = new Subject(); readonly fxBtnClick$ = this._fxBtnClick$.asObservable(); - private readonly _foldBtnStatus$ = new BehaviorSubject(false); + private readonly _foldBtnStatus$ = new Subject(); readonly foldBtnStatus$ = this._foldBtnStatus$.asObservable(); dispose(): void { diff --git a/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts b/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts index 170465b8e68..5ba6f547a09 100644 --- a/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts +++ b/packages/sheets-zen-editor/src/controllers/zen-editor.controller.ts @@ -71,7 +71,7 @@ export class ZenEditorController extends RxDisposable { this._commandExecutedListener(); - this._createZenEditorInstance(); + // this._createZenEditorInstance(); } private _createZenEditorInstance() { @@ -142,7 +142,14 @@ export class ZenEditorController extends RxDisposable { }); } + private _zenEditorInitialState = false; + private _handleOpenZenEditor() { + if (!this._zenEditorInitialState) { + this._createZenEditorInstance(); + this._zenEditorInitialState = true; + } + this._zenZoneService.open(); // Need to clear undo/redo service when open zen mode.