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(sheets-ui): clear cell image edited by backspace (#7117)

wpxp12345618e511e5408b
diff --git a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
index ea61ec5b9d..43d7fabf8d 100644
--- a/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/editor/editing.render-controller.ts
@@ -117,6 +117,8 @@ export class EditingRenderController extends Disposable {
/** If the corresponding unit is active and prepared for editing. */
private _editingUnit = '';
+ private _submitEmptyCellImageEdit = false;
+
_cursorTimeout: NodeJS.Timeout;
constructor(
@@ -475,7 +477,10 @@ export class EditingRenderController extends Disposable {
}
);
};
- if (this._isCellImageData(documentDataModel.getSnapshot())) {
+ const isCellImage = this._isCellImageData(documentDataModel.getSnapshot());
+ this._submitEmptyCellImageEdit = isCellImage && eventType === DeviceInputEventType.Keyboard && keycode === KeyCode.BACKSPACE;
+
+ if (isCellImage) {
clearAndEdit();
} else if (eventType === DeviceInputEventType.Keyboard && keycode === KeyCode.F2) {
// f2, continue to edit
@@ -537,6 +542,8 @@ export class EditingRenderController extends Disposable {
const documentDataModel = this._univerInstanceService.getUnit<DocumentDataModel>(DOCS_NORMAL_EDITOR_UNIT_ID_KEY);
const snapshot = Tools.deepClone(documentDataModel?.getSnapshot());
const { keycode } = param;
+ const shouldSubmitEmptyCellImageEdit = this._submitEmptyCellImageEdit;
+ this._submitEmptyCellImageEdit = false;
this._cursorChange = CursorChange.InitialState;
const currentUnitId = editCellState?.unitId ?? '';
this._exitInput(param);
@@ -578,7 +585,7 @@ export class EditingRenderController extends Disposable {
? this._isCellImageData(editCellState.documentLayoutObject.documentModel.getSnapshot())
: false;
- if (snapshot && !(isEmpty && isCellImage)) {
+ if (snapshot && shouldSubmitCellEdit({ isEmpty, isCellImage, shouldSubmitEmptyCellImageEdit })) {
const res = await this._submitEdit(snapshot, keycode === (MetaKeys.CTRL_COMMAND | KeyCode.ENTER) || keycode === (MetaKeys.MAC_CTRL | KeyCode.ENTER));
if (res === false) return; // if the submit was rejected, don't move selection
}
@@ -972,6 +979,22 @@ export function isRichText(body: IDocumentBody): boolean {
);
}
+export function shouldSubmitCellEdit({
+ isEmpty,
+ isCellImage,
+ shouldSubmitEmptyCellImageEdit,
+}: {
+ isEmpty?: boolean;
+ isCellImage: boolean;
+ shouldSubmitEmptyCellImageEdit: boolean;
+}): boolean {
+ if (!isEmpty || !isCellImage) {
+ return true;
+ }
+
+ return shouldSubmitEmptyCellImageEdit;
+}
+
export function getCellStyleBySnapshot(snapshot: IDocumentData): Nullable<IStyleData> {
const { body } = snapshot;
if (!body) return null;