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(selection): exit edit mode,activate cell

Dushusir9cc5f2877978
diff --git a/examples/univer-doc-ts/index.html b/examples/univer-doc-ts/index.html
index bb6e897055..fa4a3a321f 100644
--- a/examples/univer-doc-ts/index.html
+++ b/examples/univer-doc-ts/index.html
@@ -17,7 +17,7 @@
<body>
<div id="app" style="z-index: 1; position: fixed; font-size: 20px; color: green;"></div>
- <div id="univerdoc" style="height: 100vh;width: 300px;"></div>
+ <div id="univerdoc" style="height: 100vh;width: 100%;"></div>
<script type="module" src="./src/main.tsx"></script>
</body>
diff --git a/examples/univer-doc-ts/src/main.tsx b/examples/univer-doc-ts/src/main.tsx
index a65d29fe18..d7fedcdce0 100644
--- a/examples/univer-doc-ts/src/main.tsx
+++ b/examples/univer-doc-ts/src/main.tsx
@@ -27,24 +27,4 @@ univer.install(
},
},
})
-);
-
-document.querySelector('#univerdoc').style.width = '100%'
-
-// setTimeout(() => {
-// univerdoc._context
-// .getPluginManager()
-// .getRequirePluginByName('document').getDocsView().scrollToCenter();
-// // .getRequirePluginByName('document').getDocsView().getDocs().calculatePagePosition();
-// }, 500);
-
-// univerdoc.installPlugin(new DocPlugin());
-
-
-window.addEventListener('resize', function (event) {
- console.log('resize doc')
- univerdoc._context
- .getPluginManager()
- .getRequirePluginByName('document').getDocsView().scrollToCenter();
- // .getRequirePluginByName('document').getDocsView().getDocs().calculatePagePosition();
-}, true);
+);
\ No newline at end of file
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
index 052910ac65..04c3601985 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
@@ -566,7 +566,6 @@ export class SelectionManager {
if (oldStartColumn !== finalStartColumn || oldStartRow !== finalStartRow || oldEndColumn !== finalEndColumn || oldEndRow !== finalEndRow) {
selectionControl && selectionControl.update(newSelectionRange);
-
selectionControl && this._plugin.getObserver('onChangeSelectionObserver')?.notifyObservers(selectionControl);
}
@@ -593,6 +592,8 @@ export class SelectionManager {
this.setSelectionModel();
}
}
+
+ this.updatePreviousSelection();
}
}
@@ -606,7 +607,6 @@ export class SelectionManager {
// update model
this.moving(upEvt, selectionControl, true);
- this.updatePreviousSelection();
}
updatePreviousSelection() {
@@ -846,8 +846,34 @@ export class SelectionManager {
const scrollTimer = ScrollTimer.create(this.getScene());
scrollTimer.startScroll(evtOffsetX, evtOffsetY);
- // update model
- // this.setSelectionModel();
+ // In edit mode, click other cells, you need to update the current model, otherwise when updating the cell value, the old active range will be redrawn
+ const currentModel = selectionControl.getCurrentCellInfo();
+ if (!this._previousSelection) {
+ // this.setSelectionModel();
+ const models = this._selectionControls.map((control) => control.model.getValue());
+ this.setModels(models);
+ } else {
+ // If it is different from the range when clicked, you need to update the model
+ const {
+ startRow: mouseDownStartRow,
+ endRow: mouseDownEndRow,
+ startColumn: mouseDownStartColumn,
+ endColumn: mouseDownEndColumn,
+ } = (this._previousSelection.selection as IRangeData) || DEFAULT_SELECTION;
+ const { row: mouseDownRow, column: mouseDownColumn } = (this._previousSelection.cell as IRangeCellData) || DEFAULT_CELL;
+ if (
+ mouseDownStartColumn !== currentModel?.startColumn ||
+ mouseDownStartRow !== currentModel?.startRow ||
+ mouseDownEndColumn !== currentModel?.endColumn ||
+ mouseDownEndRow !== currentModel?.endRow ||
+ mouseDownRow !== currentModel?.startRow ||
+ mouseDownColumn !== currentModel?.startColumn
+ ) {
+ // this.setSelectionModel();
+ const models = this._selectionControls.map((control) => control.model.getValue());
+ this.setModels(models);
+ }
+ }
// Notification toolbar updates button state and value
this._plugin.getObserver('onChangeSelectionObserver')?.notifyObservers(selectionControl);