Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix: change element to save editing state & update doc sk after resize (#2950)

lumix35b0bace8971
diff --git a/packages/engine-render/src/engine.ts b/packages/engine-render/src/engine.ts
index 3a3c6d1ac2..c8542d6410 100644
--- a/packages/engine-render/src/engine.ts
+++ b/packages/engine-render/src/engine.ts
@@ -238,6 +238,11 @@ export class Engine extends ThinEngine<Scene> {
this.resizeBySize(width, height);
}
+ /**
+ * set canvas element size
+ * @param width
+ * @param height
+ */
resizeBySize(width: number, height: number) {
const preWidth = this.width;
const preHeight = this.height;
diff --git a/packages/engine-render/src/layer.ts b/packages/engine-render/src/layer.ts
index 185b3aeff4..9e2c18c16a 100644
--- a/packages/engine-render/src/layer.ts
+++ b/packages/engine-render/src/layer.ts
@@ -71,6 +71,10 @@ export class Layer extends Disposable {
return this._allowCache;
}
+ /**
+ * get objects which is visible and not in a group.
+ * @returns BaseObject[]
+ */
getObjectsByOrder() {
const objects: BaseObject[] = [];
this._objects.sort(sortRules);
diff --git a/packages/engine-render/src/scene.ts b/packages/engine-render/src/scene.ts
index ad8e61fd14..3aa9b6e3fd 100644
--- a/packages/engine-render/src/scene.ts
+++ b/packages/engine-render/src/scene.ts
@@ -443,6 +443,10 @@ export class Scene extends ThinScene {
return objects;
}
+ /**
+ * get objects which is visible and not in a group in each layer.
+ * @returns BaseObject[]
+ */
getAllObjects() {
const objects: BaseObject[] = [];
this._layers.sort(sortRules);
@@ -452,6 +456,11 @@ export class Scene extends ThinScene {
return objects;
}
+ /**
+ * get objects which is visible and not in a group.
+ * @param isDesc
+ * @returns BaseObject[]
+ */
getAllObjectsByOrder(isDesc: boolean = false) {
const objects: BaseObject[] = [];
const useSortRules = isDesc ? sortRulesByDesc : sortRules;
diff --git a/packages/engine-render/src/shape/rich-text.ts b/packages/engine-render/src/shape/rich-text.ts
index 59d74f5757..0d99bd67e5 100644
--- a/packages/engine-render/src/shape/rich-text.ts
+++ b/packages/engine-render/src/shape/rich-text.ts
@@ -194,6 +194,9 @@ export class RichText extends BaseObject {
return this._documentData;
}
+ /**
+ * get last page size
+ */
getDocsSkeletonPageSize() {
const skeletonData = this._documentSkeleton?.getSkeletonData();
@@ -207,6 +210,10 @@ export class RichText extends BaseObject {
return { width, height };
}
+ /**
+ * this[`_${key}`] = props[key];
+ * @param props
+ */
setProps(props?: IRichTextProps) {
if (!props) {
return;
@@ -326,6 +333,7 @@ export class RichText extends BaseObject {
const contentSize = this.getDocsSkeletonPageSize();
+ // this[pKey] = option[pKey]
this.transformByState({
width: contentSize?.width || 0,
height: contentSize?.height || 0,
@@ -334,13 +342,18 @@ export class RichText extends BaseObject {
angle: props?.angle,
});
+ // this[`_${key}`] = props[key];
this.setProps(props);
this.makeDirty(true);
}
/**
+ *
+ * it should be invoked when _documentData changed.
* _documentData changed ---> update _documentSkeleton & _documentSkeleton
+ *
+ * now it is invoked when transformByState(change editor size) & end of editing
*/
refreshDocumentByDocData() {
const docModel = new DocumentDataModel(this._documentData);
@@ -356,8 +369,21 @@ export class RichText extends BaseObject {
this._documentSkeleton
.getViewModel()
.getDataModel()
- .updateDocumentDataPageSize(this.width, this.height);
+ .updateDocumentDataPageSize(this.width, Infinity);
this._documentSkeleton.calculate();
}
+
+ /**
+ * invoked when end editing.
+ */
+ resizeToContentSize() {
+ const contentSize = this.getDocsSkeletonPageSize();
+ if (contentSize && contentSize.width !== 0 && contentSize.height !== 0) {
+ this.transformByState({
+ // width: contentSize?.width || 0,
+ height: contentSize?.height || 0,
+ });
+ }
+ }
}
diff --git a/packages/slides-ui/src/controllers/slide-editing.render-controller.ts b/packages/slides-ui/src/controllers/slide-editing.render-controller.ts
index 2af622dc2a..d04bb620f6 100644
--- a/packages/slides-ui/src/controllers/slide-editing.render-controller.ts
+++ b/packages/slides-ui/src/controllers/slide-editing.render-controller.ts
@@ -20,7 +20,7 @@ import type {
IDocumentBody,
IPosition,
Nullable,
- Workbook,
+ UnitModel,
} from '@univerjs/core';
import {
DEFAULT_EMPTY_DOCUMENT_VALUE,
@@ -32,7 +32,6 @@ import {
FOCUSING_EDITOR_BUT_HIDDEN,
FOCUSING_EDITOR_INPUT_FORMULA,
FOCUSING_EDITOR_STANDALONE,
- FOCUSING_SHEET,
FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE,
FORMULA_EDITOR_ACTIVATED,
HorizontalAlign,
@@ -55,6 +54,7 @@ import {
DocSkeletonManagerService,
MoveCursorOperation,
MoveSelectionOperation,
+ RichTextEditingMutation,
TextSelectionManagerService,
} from '@univerjs/docs';
// import { IFunctionService, LexerTreeBuilder } from '@univerjs/engine-formula';
@@ -70,7 +70,6 @@ import type {
} from '@univerjs/engine-render';
import {
convertTextRotation,
- DeviceInputEventType,
FIX_ONE_PIXEL_BLUR_OFFSET,
fixLineWidthByScale,
IRenderManagerService,
@@ -117,8 +116,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
private _d: Nullable<IDisposable>;
constructor(
- private readonly _context: IRenderContext<Workbook>,
- // @Inject(SheetsSelectionsService) selectionManagerService: SheetsSelectionsService,
+ private readonly _renderContext: IRenderContext<UnitModel>,
@IUndoRedoService private readonly _undoRedoService: IUndoRedoService,
@IContextService private readonly _contextService: IContextService,
@IUniverInstanceService private readonly _instanceSrv: IUniverInstanceService,
@@ -205,22 +203,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
if (!renderConfig) return;
d.add(renderConfig.document.onPointerDown$.subscribeEvent(() => {
- // fix https://github.com/dream-num/univer/issues/628, need to recalculate the cell editor size after
- // it acquire focus.
- // if (this._isUnitEditing && this._editorBridgeService.isVisible()) {
- // const param = this._editorBridgeService.getEditRectState();
- // const editorId = this._editorBridgeService.getCurrentEditorId();
-
- // if (!param || !editorId || !this._editorService.isSheetEditor(editorId)) {
- // return;
- // }
-
- // const skeleton = this._getEditorSkeleton(editorId);
- // if (!skeleton) return;
-
- // const { position, documentLayoutObject, canvasOffset, scaleX, scaleY } = param;
- // this._fitTextSize(position, canvasOffset, skeleton, documentLayoutObject, scaleX, scaleY);
- // }
+ // ...
}));
}
@@ -239,19 +222,18 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
}
/**
- * Should update current editing cell info when selection is changed.
+ * Set editorUnitId to curr doc.
* @param d DisposableCollection
*/
private _subscribeToCurrentCell(d: DisposableCollection) {
// first part of editing.
// startEditing --> _updateEditor --> slide-editor-bridge.service.ts@setEditorRect---> currentEditRectState$.next(editCellState)
- // startEditing --> changeVisible
+ // 2nd part is startEditing --> changeVisible
d.add(this._editorBridgeService.currentEditRectState$.subscribe((editCellState) => {
if (editCellState == null) {
return;
}
- const { position, documentLayoutObject, scaleX, editorUnitId } = editCellState;
if (
this._contextService.getContextValue(FOCUSING_EDITOR_STANDALONE) ||
this._contextService.getContextValue(FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE)
@@ -259,8 +241,12 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
return;
}
- const { startX, endX } = position;
- const { textRotation, wrapStrategy, documentModel } = documentLayoutObject;
+ const {
+ position: { startX, endX },
+ documentLayoutObject: { textRotation, wrapStrategy, documentModel },
+ scaleX,
+ editorUnitId,
+ } = editCellState;
const { vertexAngle: angle } = convertTextRotation(textRotation);
documentModel!.updateDocumentId(editorUnitId);
@@ -275,26 +261,42 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
endOffset: 0,
}]);
- // the last active, calling stack trace:
- // EditorContainer.tsx cellEditorManagerService.state$.subscribe -->
+ // the valid pos of activate:
// EditorContainer.tsx cellEditorManagerService.setFocus(true) -->
- // _textSelectionRenderManager.sync() --> _updateInputPosition --> activate
+ // ---> _focus$.next --> editingRenderController
+ // _textSelectionRenderManager.sync() --> _updateInputPosition --> activate(left, top)
- // hide the editor, but the editor is still exist.
- // the last and valid call activate is in _textSelectionRenderManager.sync() --> _updateInputPosition
this._textSelectionRenderManager.activate(HIDDEN_EDITOR_POSITION, HIDDEN_EDITOR_POSITION);
}));
}
+ /**
+ * set size and pos of editing area
+ * invoked by _handleEditorVisible
+ *
+ * size & pos derives from [email protected]
+ *
+ * set pos of editing area
+ * EditorContainer.tsx cellEditorManagerService.setFocus(true) -->
+ * _focus$.next --> editingRenderController -->
+ * _textSelectionRenderManager.sync() --> _updateInputPosition --> activate(left, top)
+ *
+ * @param positionFromEditRectState
+ * @param canvasOffset
+ * @param documentSkeleton
+ * @param documentLayoutObject
+ * @param scaleX
+ * @param scaleY
+ */
private _fitTextSize(
- actualRangeWithCoord: IPosition,
+ positionFromEditRectState: IPosition,
canvasOffset: ICanvasOffset,
documentSkeleton: DocumentSkeleton,
documentLayoutObject: IDocumentLayoutObject,
scaleX: number = 1,
scaleY: number = 1
) {
- const { startX, startY, endX, endY } = actualRangeWithCoord;
+ const { startX, startY, endX, endY } = positionFromEditRectState;
const documentDataModel = documentLayoutObject.documentModel;
if (documentDataModel == null) {
@@ -302,7 +304,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
}
const { actualWidth, actualHeight } = this._predictingSize(
- actualRangeWithCoord,
+ positionFromEditRectState,
canvasOffset,
documentSkeleton,
documentLayoutObject,
@@ -346,7 +348,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
// re-calculate skeleton(viewModel for component)
documentSkeleton.calculate();
- this._editAreaProcessing(editorWidth, editorHeight, actualRangeWithCoord, canvasOffset, fill, scaleX, scaleY);
+ this._editAreaProcessing(editorWidth, editorHeight, positionFromEditRectState, canvasOffset, fill, scaleX, scaleY);
}
/**
@@ -410,15 +412,13 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
}
/**
- * Mainly used to calculate the volume of scenes and objects,
- * determine whether a scrollbar appears,
- * and calculate the editor's boundaries relative to the browser.
+ * control the size of editing area
*/
// eslint-disable-next-line max-lines-per-function
private _editAreaProcessing(
editorWidth: number,
editorHeight: number,
- actualRangeWithCoord: IPosition,
+ positionFromEditRectState: IPosition,
canvasOffset: ICanvasOffset,
fill: Nullable<string>,
scaleX: number = 1,
@@ -430,7 +430,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
return;
}
- let { startX, startY } = actualRangeWithCoord;
+ let { startX, startY } = positionFromEditRectState;
startX += canvasOffset.left;
startY += canvasOffset.top;
@@ -466,9 +466,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
editorWidth += scrollBar?.barSize || 0;
- if (editorWidth > clientWidth) {
- editorWidth = clientWidth;
- }
+ editorWidth = Math.min(editorWidth, clientWidth);
startX -= FIX_ONE_PIXEL_BLUR_OFFSET;
@@ -562,14 +560,14 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
* startEditing --> changeVisible --> slide-editor-bridge.render-controller.ts@changeVisible --> _editorBridgeService.changeVisible
* @param param
*/
- private _handleEditorVisible(param: IEditorBridgeServiceVisibleParam) {
- const { eventType, keycode } = param;
+ private _handleEditorVisible(_param: IEditorBridgeServiceVisibleParam) {
+ // const { eventType, keycode } = param;
// Change `CursorChange` to changed status, when formula bar clicked.
- this._cursorChange =
- eventType === DeviceInputEventType.PointerDown
- ? CursorChange.CursorChange
- : CursorChange.StartEditor;
+ // this._cursorChange =
+ // eventType === DeviceInputEventType.PointerDown
+ // ? CursorChange.CursorChange
+ // : CursorChange.StartEditor;
const editCellState = this._editorBridgeService.getEditRectState();
if (editCellState == null) {
@@ -584,8 +582,6 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
scaleY,
editorUnitId,
unitId,
- // sheetId,
- // isInArrayFormulaRange = false,
} = editCellState;
const editorObject = this._getEditorObject();
@@ -594,9 +590,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
return;
}
- // this._setOpenForCurrent(unitId, sheetId);
-
- const { document, scene } = editorObject;
+ const { scene } = editorObject;
this._contextService.setContextValue(EDITOR_ACTIVATED, true);
@@ -606,6 +600,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
return;
}
+ // core function! set editing area size and pos
this._fitTextSize(position, canvasOffset, skeleton, documentLayoutObject, scaleX, scaleY);
// TODO: @JOCS, Get the position close to the cursor after clicking on the cell.
@@ -672,14 +667,14 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
*/
private _initialKeyboardListener(d: DisposableCollection) {
d.add(this._textSelectionRenderManager.onInputBefore$.subscribe((config) => {
- const isFocusFormulaEditor = this._contextService.getContextValue(FORMULA_EDITOR_ACTIVATED);
- const isFocusSheets = this._contextService.getContextValue(FOCUSING_SHEET);
+ // const isFocusFormulaEditor = this._contextService.getContextValue(FORMULA_EDITOR_ACTIVATED);
+ // const isFocusSheets = this._contextService.getContextValue(FOCUSING_SHEET);
- // TODO@Jocs: should get editor instead of current doc
- const unitId = this._instanceSrv.getCurrentUniverDocInstance()?.getUnitId();
- if (unitId && isFocusSheets && !isFocusFormulaEditor && this._editorService.isSheetEditor(unitId)) {
- this._showEditorByKeyboard(config);
- }
+ // // TODO@Jocs: should get editor instead of current doc
+ // const unitId = this._instanceSrv.getCurrentUniverDocInstance()?.getUnitId();
+ // if (unitId && isFocusSheets && !isFocusFormulaEditor && this._editorService.isSheetEditor(unitId)) {
+ // this._showEditorByKeyboard(config);
+ // }
}));
}
@@ -698,49 +693,59 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
// });
}
- /**
- * Listen to document edits to refresh the size of the sheet editor, not for normal editor.
- */
private _commandExecutedListener(d: DisposableCollection) {
const moveCursorOP = [SetTextEditArrowOperation.id];
+ const editedMutations = [RichTextEditingMutation.id];
d.add(this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (moveCursorOP.includes(command.id)) {
- const params = command.params as IEditorBridgeServiceVisibleParam & { isShift: boolean };
- const { keycode, isShift } = params;
-
- /**
- * After the user enters the editor and actively moves the editor selection area with the mouse,
- * the up, down, left, and right keys can no longer switch editing cells,
- * but move the cursor within the editor instead.
- */
- if (keycode != null &&
- (this._cursorChange === CursorChange.CursorChange || this._contextService.getContextValue(FORMULA_EDITOR_ACTIVATED))
- ) {
- this._moveInEditor(keycode, isShift);
- return;
- }
-
- // TODO@Jocs: After we merging editor related controllers, this seems verbose.
- // We can directly call SetRangeValues here.
- this._editorBridgeService.changeVisible(params);
+ this._moveCursorCmdHandler(command);
+ }
+ if (editedMutations.includes(command.id)) {
+ this._editingChangedHandler();
}
-
- // if (command.id === SetCellEditVisibleWithF2Operation.id) {
- // this._cursorChange = CursorChange.CursorChange;
- // }
}));
}
- private _setOpenForCurrent(unitId: Nullable<string>, sheetId: Nullable<string>) {
- const sheetEditors = this._editorService.getAllEditor();
- for (const [_, sheetEditor] of sheetEditors) {
- if (!sheetEditor.isSheetEditor()) {
- continue;
- }
+ private _moveCursorCmdHandler(command: ICommandInfo) {
+ const params = command.params as IEditorBridgeServiceVisibleParam & { isShift: boolean };
+ const { keycode, isShift } = params;
+
+ /**
+ * After the user enters the editor and actively moves the editor selection area with the mouse,
+ * the up, down, left, and right keys can no longer switch editing cells,
+ * but move the cursor within the editor instead.
+ */
+ if (keycode != null &&
+ (this._cursorChange === CursorChange.CursorChange || this._contextService.getContextValue(FORMULA_EDITOR_ACTIVATED))
+ ) {
+ this._moveInEditor(keycode, isShift);
+ return;
+ }
- sheetEditor.setOpenForSheetUnitId(unitId);
- sheetEditor.setOpenForSheetSubUnitId(sheetId);
+ // TODO @Jocs: After we merging editor related controllers, this seems verbose.
+
+ this._editorBridgeService.changeVisible(params);
+ }
+
+ private _editingChangedHandler() {
+ const editingRichText = this._editorBridgeService.getEditorRect().richTextObj;
+ editingRichText.refreshDocumentByDocData();
+ editingRichText.resizeToContentSize();
+
+ const { unitId } = this._renderContext;
+ this._handleEditorVisible({ visible: true, eventType: 3, unitId });
+ }
+
+ private _setOpenForCurrent(unitId: Nullable<string>, subUnitId: Nullable<string>) {
+ const editors = this._editorService.getAllEditor();
+ for (const [_, ed] of editors) {
+ // if (!ed.isSheetEditor()) {
+ // continue;
+ // }
+
+ ed.setOpenForSheetUnitId(unitId);
+ ed.setOpenForSheetSubUnitId(subUnitId);
}
}
@@ -762,7 +767,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
return;
}
- const { unitId, documentLayoutObject } = editCellState;
+ // const { unitId, documentLayoutObject } = editCellState;
// If neither the formula bar editor nor the cell editor has been edited,
// it is considered that the content has not changed and returns directly.
@@ -772,11 +777,6 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
return;
}
- // const workbook = this._context.unit;
- // const worksheet = workbook.getActiveSheet();
- // const workbookId = this._context.unitId;
- // const worksheetId = worksheet.getSheetId();
-
// moveCursor need to put behind of SetRangeValuesCommand, fix https://github.com/dream-num/univer/issues/1155
this._moveCursor(keycode);
}
@@ -791,7 +791,7 @@ export class SlideEditingRenderController extends Disposable implements IRenderM
show: param.visible,
});
const editorUnitId = this._editorBridgeService.getCurrentEditorId();
- if (editorUnitId == null || !this._editorService.isSheetEditor(editorUnitId)) {
+ if (editorUnitId == null) {
return;
}
this._undoRedoService.clearUndoRedo(editorUnitId);
diff --git a/packages/slides-ui/src/controllers/slide-editor-bridge.render-controller.ts b/packages/slides-ui/src/controllers/slide-editor-bridge.render-controller.ts
index d240e655af..92e15c8b0e 100644
--- a/packages/slides-ui/src/controllers/slide-editor-bridge.render-controller.ts
+++ b/packages/slides-ui/src/controllers/slide-editor-bridge.render-controller.ts
@@ -77,7 +77,8 @@ export class SlideEditorBridgeRenderController extends RxDisposable implements I
// }));
}
- private _updateEditor(targetObject: RichText) {
+ private _setEditorRect(targetObject: RichText) {
+ this._curRichText = targetObject as RichText;
const { scene, engine } = this._renderContext;
const unitId = this._renderContext.unitId;
@@ -115,10 +116,10 @@ export class SlideEditorBridgeRenderController extends RxDisposable implements I
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) {
+ if (target === this._curRichText) {
// do nothing
+ } else {
+ this.pickOtherObjects();
}
}));
@@ -154,6 +155,7 @@ export class SlideEditorBridgeRenderController extends RxDisposable implements I
const slideData = this._instanceSrv.getCurrentUnitForType<SlideDataModel>(UniverInstanceType.UNIVER_SLIDE);
if (!slideData) return false;
curRichText.refreshDocumentByDocData();
+ curRichText.resizeToContentSize();
this._curRichText = null;
}
@@ -166,8 +168,8 @@ export class SlideEditorBridgeRenderController extends RxDisposable implements I
*/
startEditing(target: RichText) {
// this.setSlideTextEditor$.next({ content, rect });
- this._curRichText = target as RichText;
- this._updateEditor(target);
+
+ this._setEditorRect(target);
this.setEditorVisible(true);
}
diff --git a/packages/slides-ui/src/services/slide-editor-bridge.service.ts b/packages/slides-ui/src/services/slide-editor-bridge.service.ts
index f2b4372907..e9a994e977 100644
--- a/packages/slides-ui/src/services/slide-editor-bridge.service.ts
+++ b/packages/slides-ui/src/services/slide-editor-bridge.service.ts
@@ -46,6 +46,10 @@ export const ISlideEditorBridgeService = createIdentifier<SlideEditorBridgeServi
export interface IEditorBridgeServiceParam {
unitId: string;
+
+ /**
+ * pos and size of editing area
+ */
position: IPosition;
slideCardOffset: { left: number; top: number };
documentLayoutObject: IDocumentLayoutObject;
@@ -81,6 +85,7 @@ export interface ISlideEditorBridgeService {
// refreshEditCellState(): void;
setEditorRect(param: ISetEditorInfo): void;
+ getEditorRect(): ISetEditorInfo;
getEditRectState(): Readonly<Nullable<IEditorBridgeServiceParam>>;
// // Gets the DocumentDataModel of the latest table cell based on the latest cell contents
// getLatestEditCellState(): Readonly<Nullable<IEditorBridgeServiceParam>>;
@@ -129,7 +134,12 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
super.dispose();
}
+ getEditorRect() {
+ return this._currentEditRectInfo;
+ }
+
/**
+ * 1st part of startEditing.
* editorBridgeRenderController@startEditing ---> editorBridgeRenderController@_updateEditor
* @editorInfo editorInfo
*/
@@ -138,7 +148,7 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
/**
* If there is no editor currently focused, then default to selecting the sheet editor to prevent the editorService from using the previously selected editor object.
- * todo: wzhudev: In boundless mode, it is necessary to switch to the corresponding editorId based on the host's unitId.
+ * todo: wzhudev: In univer mode, it is necessary to switch to the corresponding editorId based on the host's unitId.
*/
if (!this._editorService.getFocusEditor()) {
this._editorService.focus(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
@@ -147,11 +157,12 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
this._contextService.setContextValue(FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, false);
}
- const editCellState = this.getEditRectState();
- this._currentEditRectState = editCellState;
+ const editRectState = this.getEditRectState();
+ this._currentEditRectState = editRectState;
- // slide-editing.render-controller.ts@_subscribeToCurrentCell --> activate(-1000, -1000)
- this._currentEditRectState$.next(editCellState);
+ // slide-editing.render-controller@_subscribeToCurrentCell(Set editorUnitId to curr doc.)
+ // --> activate(-1000, -1000)
+ this._currentEditRectState$.next(editRectState);
}
changeVisible(param: IEditorBridgeServiceVisibleParam) {
@@ -171,7 +182,7 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
this._editorIsDirty = false;
}
- // subscribe: editing render controller
+ // subscriber: slide-editing.render-controller.ts@_handleEditorVisible
this._visible$.next(this._visible);
this._afterVisible$.next(this._visible);
}
@@ -179,7 +190,8 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
/**
* get info from _currentEditRectInfo
*
- * invoked by slide-editing.render-controller.ts@_handleEditorVisible & this@setEditorRect
+ * invoked by slide-editing.render-controller.ts@_handleEditorVisible
+ * && this@setEditorRect
*/
getEditRectState(): Readonly<Nullable<IEditorBridgeServiceParam>> {
const editorUnitId = DOCS_NORMAL_EDITOR_UNIT_ID_KEY;
@@ -195,7 +207,7 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
docData.documentStyle = {
...docData.documentStyle,
...{
- pageSize: { width: Infinity, height: Infinity },
+ pageSize: { width: editorRectInfo.richTextObj.width, height: Infinity },
},
};
@@ -211,7 +223,6 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
};
// see insert-text.operation
- // TODO: @lumixraku need to plus scrolling and offset of PPT card.
const editorWidth = editorRectInfo.richTextObj.width;
const editorHeight = editorRectInfo.richTextObj.height;
const left = editorRectInfo.richTextObj.left;
@@ -249,7 +260,7 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
unitId,
editorUnitId,
documentLayoutObject,
- };
+ } as IEditorBridgeServiceParam;
}
changeEditorDirty(dirtyStatus: boolean) {