Skip to content

Commit

Permalink
fix: change element to save editing state & update doc sk after resize
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Aug 6, 2024
1 parent 297cf6d commit 3aa6f48
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 11 deletions.
4 changes: 4 additions & 0 deletions packages/engine-render/src/base-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ export abstract class BaseObject extends Disposable {
return this;
}

/**
* this[pKey] = option[pKey]
* @param option
*/
transformByState(option: IObjectFullState) {
const optionKeys = Object.keys(option);
const preKeys: IObjectFullState = {};
Expand Down
48 changes: 42 additions & 6 deletions packages/engine-render/src/shape/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,68 @@ export class RichText extends BaseObject {

private _documents!: Documents;

/**
* fontFamily
*/
private _ff?: Nullable<string>;

/**
* fontSize
* pt
*/
private _fs?: number = 12;

/**
* italic
* 0: false
* 1: true
*/
private _it?: BooleanNumber = BooleanNumber.FALSE;

/**
* bold
* 0: false
* 1: true
*/
private _bl?: BooleanNumber = BooleanNumber.FALSE;

/**
* underline
*/
private _ul?: ITextDecoration = {
s: BooleanNumber.FALSE,
};

/**
* strikethrough
*/
private _st?: ITextDecoration = {
s: BooleanNumber.FALSE,
};

/**
* overline
*/
private _ol?: ITextDecoration = {
s: BooleanNumber.FALSE,
};

/**
* background
*/
private _bg?: Nullable<IColorStyle>;

/**
* border
*/
private _bd?: Nullable<IBorderData>;

/**
* foreground
*/
private _cl?: Nullable<IColorStyle>;

override objectType = ObjectType.RICH_TEXT;
private _originProps: IRichTextProps;

constructor(
private _localeService: LocaleService,
Expand All @@ -108,8 +142,6 @@ export class RichText extends BaseObject {
this._bd = props.bd;
this._cl = props.cl;

this._originProps = props;

this._documentData = this._convertToDocumentData(props.text || '');
}

Expand All @@ -134,6 +166,8 @@ export class RichText extends BaseObject {
const size = this.getDocsSkeletonPageSize();
this.height = size?.height || this.height;
this._setTransForm();

this.refreshDocumentByDocData();
}
});
}
Expand Down Expand Up @@ -305,7 +339,10 @@ export class RichText extends BaseObject {
this.makeDirty(true);
}

updateDocumentByDocData() {
/**
* _documentData changed ---> update _documentSkeleton & _documentSkeleton
*/
refreshDocumentByDocData() {
const docModel = new DocumentDataModel(this._documentData);
const docViewModel = new DocumentViewModel(docModel);

Expand All @@ -316,11 +353,10 @@ export class RichText extends BaseObject {
pageMarginTop: 0,
});

const props = this._originProps;
this._documentSkeleton
.getViewModel()
.getDataModel()
.updateDocumentDataPageSize(props?.width, props?.height);
.updateDocumentDataPageSize(this.width, this.height);

this._documentSkeleton.calculate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,36 @@ export class SlideEditorBridgeRenderController extends RxDisposable implements I
this.setEditorVisible(false);
}));

d.add(transformer.changeStart$.subscribe((param: IChangeObserverConfig) => {
const target = param.target;
if (!target) return;
if (target.objectType !== ObjectType.RICH_TEXT) {
this.pickOtherObjects();
} else if (target === this._curRichText) {
// do nothing
}
}));

d.add(scene.onDblclick$.subscribeEvent(() => {
transformer.clearControls();
const selectedObjects = transformer.getSelectedObjectMap();
const object = selectedObjects.values().next().value as Nullable<BaseObject>;
if (!object) return;

if (object.objectType !== ObjectType.RICH_TEXT) {
this.setEditorVisible(false);
this.endEditing();
this.pickOtherObjects();
} else {
this.startEditing(object as RichText);
}
}));
}
}

pickOtherObjects() {
this.setEditorVisible(false);
this.endEditing();
}

/**
* invoked when picking other object.
*
Expand All @@ -139,7 +153,7 @@ export class SlideEditorBridgeRenderController extends RxDisposable implements I

const slideData = this._instanceSrv.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
if (!slideData) return false;
curRichText.updateDocumentByDocData();
curRichText.refreshDocumentByDocData();
this._curRichText = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
EDITOR_ACTIVATED,
FOCUSING_EDITOR_STANDALONE,
FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE,
HorizontalAlign,
IContextService,
VerticalAlign,
} from '@univerjs/core';
Expand Down Expand Up @@ -204,8 +205,8 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
fontString: 'document',
textRotation: { a: 0, v: 0 },
wrapStrategy: 0,
verticalAlign: VerticalAlign.MIDDLE,
horizontalAlign: 0,
verticalAlign: VerticalAlign.TOP,
horizontalAlign: HorizontalAlign.LEFT,
paddingData: { t: 0, b: 1, l: 2, r: 2 },
};

Expand Down Expand Up @@ -267,6 +268,9 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
return this._editorUnitId;
}

/**
* @deprecated
*/
genDocData(target: RichText) {
const editorUnitId = this.getCurrentEditorId();
const content = target.text;
Expand Down

0 comments on commit 3aa6f48

Please sign in to comment.