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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feature(base-sheets): add setCurrentCell API
Dushusir9fca2e424302
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsxindex ad71ad5ee6..dc162e5e50 100644--- a/examples/univer-sheet-ts/src/main.tsx+++ b/examples/univer-sheet-ts/src/main.tsx@@ -72,6 +72,7 @@ univer.install(}}));+// FormulaPlugin.create(DEFAULT_FORMULA_DATA_DEMO).installTo(universheet);FindPlugin.create().installTo(universheet);// sheets-plugin-ui univer.install(new SheetsUI)diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.tsindex ddd16f382b..052910ac65 100644--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts@@ -16,6 +16,7 @@ import {ISelectionData,DEFAULT_SELECTION,DEFAULT_CELL,+ IGridRange,} from '@univerjs/core';import { ACTION_NAMES, ISelectionsConfig } from '../../Basics';import { ISelectionModelValue, ISetSelectionValueActionData, SetSelectionValueAction } from '../../Model/Action/SetSelectionValueAction';@@ -469,6 +470,51 @@ export class SelectionManager {this.updatePreviousSelection();}+ setCurrentCell(gridData: IGridRange): void {+ const { rangeData: girdRangeData, sheetId } = gridData;+ const { startRow: row, startColumn: column } = girdRangeData;++ // active new target sheet+ const currentSheetId = this.getWorksheetId();+ if (sheetId !== currentSheetId) {+ const sheetIndex = this._worksheet?.getIndex();+ if (sheetIndex == null) return;+ this._plugin.getWorkbook().activateSheetByIndex(sheetIndex);+ }++ const cellInfo = this._mainComponent.getCellByIndex(row, column);++ const selectionData = makeCellToSelection(cellInfo);++ if (!selectionData) return;++ const { startRow, endRow, startColumn, endColumn } = selectionData;++ const main = this._mainComponent;+ const newBounding = main.getSelectionBounding(startRow, startColumn, endRow, endColumn);++ if (!newBounding) {+ return;+ }++ const { startRow: finalStartRow, startColumn: finalStartColumn, endRow: finalEndRow, endColumn: finalEndColumn } = newBounding;++ let rangeData: IRangeData = {+ startRow: finalStartRow,+ endRow: finalEndRow,+ startColumn: finalStartColumn,+ endColumn: finalEndColumn,+ };+ let currentCellData: IRangeCellData = {+ row: startRow,+ column: startColumn,+ };++ this.clearSelectionControls();+ this.addControlToCurrentByRangeData(rangeData, currentCellData);+ this.updatePreviousSelection();+ }+/*** When mousedown and mouseup need to go to the coordination and undo stack, when mousemove does not need to go to the coordination and undo stack* @param moveEvt