Skip to content

Commit

Permalink
chore: change editor unit name
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev committed Jun 18, 2024
1 parent 48a1c9f commit 2d44a24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/common/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/

export const DOCS_NORMAL_EDITOR_UNIT_ID_KEY = '__defaultDocumentNormalEditorSpecialUnitId_20231006__';
export const DOCS_NORMAL_EDITOR_UNIT_ID_KEY = '__INTERNAL_EDITOR__DOCS_NORMAL';

export const DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY = '__defaultDocumentFormulaBarEditorSpecialUnitId_20231012__';
export const DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY = '__INTERNAL_EDITOR__DOCS_FORMULA_BAR';

export const DEFAULT_EMPTY_DOCUMENT_VALUE = '\r\n';

export function createInternalEditorID(id: string) {
return `__internalEditorId__${id}`;
return `__INTERNAL_EDITOR__${id}`;
}

export function isInternalEditorID(id: string) {
return id.startsWith('__');
return id.startsWith('__INTERNAL_EDITOR__');
}
2 changes: 1 addition & 1 deletion packages/core/src/services/instance/instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface IUniverInstanceService {
/** Subscribe to curtain type of units' creation. */
getTypeOfUnitAdded$<T extends UnitModel>(type: UnitType): Observable<T>;

/** @interal */
/** @ignore */
__addUnit(unit: UnitModel): void;

/** Omits value when a UnitModel is disposed. */
Expand Down
14 changes: 9 additions & 5 deletions packages/docs/src/services/doc-skeleton-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export class DocSkeletonManagerService extends RxDisposable implements IRenderMo
) {
super();

this._update();
this._init();

this._univerInstanceService.getCurrentTypeOfUnit$<DocumentDataModel>(UniverInstanceType.UNIVER_DOC)
.pipe(takeUntil(this.dispose$))
.subscribe((documentModel) => {
if (documentModel?.getUnitId() === this._context.unitId) {
this._update();
this._update(documentModel);
}
});
}
Expand All @@ -61,8 +61,12 @@ export class DocSkeletonManagerService extends RxDisposable implements IRenderMo
this._currentSkeleton$.complete();
}

private _update() {
private _init() {
const documentDataModel = this._context.unit;
this._update(documentDataModel);
}

private _update(documentDataModel: DocumentDataModel) {
const unitId = this._context.unitId;

// No need to build view model, if data model has no body.
Expand All @@ -73,6 +77,8 @@ export class DocSkeletonManagerService extends RxDisposable implements IRenderMo
// Always need to reset document data model, because cell editor change doc instance every time.
if (this._docViewModel && unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) {
this._docViewModel.reset(documentDataModel);

this._context.unit = documentDataModel;
} else if (!this._docViewModel) {
this._docViewModel = this._buildDocViewModel(documentDataModel);
}
Expand All @@ -86,8 +92,6 @@ export class DocSkeletonManagerService extends RxDisposable implements IRenderMo

this._currentSkeletonBefore$.next(skeleton);
this._currentSkeleton$.next(skeleton);

return this.getSkeleton();
}

getSkeleton(): DocumentSkeleton {
Expand Down

0 comments on commit 2d44a24

Please sign in to comment.