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
feat(base-sheets): selection move
Dushusir1c354072077e
diff --git a/packages/base-sheets/src/Controller/CellEditorController.ts b/packages/base-sheets/src/Controller/CellEditorController.tsindex 8e975b5e42..25e547ebd7 100644--- a/packages/base-sheets/src/Controller/CellEditorController.ts+++ b/packages/base-sheets/src/Controller/CellEditorController.ts@@ -108,6 +108,9 @@ export class CellEditorController {case 'Enter':if (this.isEditMode) {this.exitEditMode();++ // move to cell below+ // this._plugin.getSelectionManager().moveDown()} else {this.enterEditMode();}diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.tsindex 8568ab7943..1d2f319a5e 100644--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts@@ -1,5 +1,5 @@import { IMouseEvent, IPointerEvent, Rect, Spreadsheet, SpreadsheetColumnTitle, SpreadsheetRowTitle } from '@univer/base-render';-import { Nullable, Observer, Worksheet, ISelection, makeCellToSelection, IRangeData, RangeList, Range, IRangeCellData, ICellInfo, Command } from '@univer/core';+import { Nullable, Observer, Worksheet, ISelection, makeCellToSelection, IRangeData, RangeList, Range, IRangeCellData, ICellInfo, Command, Direction } from '@univer/core';import { ACTION_NAMES, ISelectionsConfig } from '../../Basics';import { ISelectionModelValue, ISetSelectionValueActionData } from '../../Model/Action/SetSelectionValueAction';import { SelectionModel } from '../../Model/SelectionModel';@@ -26,8 +26,6 @@ export class SelectionManager {private _upObserver: Nullable<Observer<IPointerEvent | IMouseEvent>>;- // private _selectionControls = new Map<string, SelectionControl[]>(); // sheetID:Controls-private _selectionControls: SelectionControl[] = []; // sheetID:Controlsprivate _selectionModels = new Map<string, SelectionModel[]>(); // sheetID:Models@@ -71,11 +69,37 @@ export class SelectionManager {return this._selectionControls;}+ getCurrentModels() {+ const worksheetId = this.getWorksheetId();+ if (!worksheetId) {+ return;+ }++ const models = this._selectionModels.get(worksheetId);++ if (!models) {+ this._selectionModels.set(worksheetId, []);+ }+ return this._selectionModels.get(worksheetId);+ }++ getCurrentModelsValue(): ISelectionModelValue[] {+ const models = this.getCurrentModels();+ if (!models) {+ return [];+ }+ const selectionModelsValue = [];+ for (let model of models) {+ selectionModelsValue.push(model.getValue());+ }+ return selectionModelsValue;+ }+/*** Renders all controls of the currently active sheet* @returns*/- renderCurrentControls() {+ renderCurrentControls(newSelectionRange?: ISelection, highlight?: Nullable<ICellInfo>) {const worksheetId = this.getWorksheetId();if (worksheetId) {if (this._selectionControls) {@@ -89,7 +113,7 @@ export class SelectionManager {const selectionModels = this._selectionModels.get(worksheetId);this._selectionControls = [];selectionModels?.forEach((model) => {- const curCellRange = model.currentCell;+ const curCellRange = highlight || model.currentCell;const main = this._mainComponent;const control = SelectionControl.create(this, this._selectionControls.length);@@ -99,7 +123,7 @@ export class SelectionManager {cellInfo = main.getCellByIndex(curCellRange.row, curCellRange.column);}- const { startRow, startColumn, endRow, endColumn } = model;+ const { startRow, startColumn, endRow, endColumn } = newSelectionRange || model;const startCell = main.getNoMergeCellPositionByIndex(startRow, startColumn);const endCell = main.getNoMergeCellPositionByIndex(endRow, endColumn);@@ -124,13 +148,6 @@ export class SelectionManager {}}- // resetCurrentModels() {- // const worksheetId = this.getWorksheetId();- // if (worksheetId) {- // this._selectionModels.set(worksheetId, []);- // }- // }-getPlugin() {return this._plugin;}@@ -237,20 +254,6 @@ export class SelectionManager {commandManager.invoke(command);}- getSelectionModels() {- const worksheetId = this.getWorksheetId();- if (!worksheetId) {- return;- }-- const models = this._selectionModels.get(worksheetId);-- if (!models) {- this._selectionModels.set(worksheetId, []);- }- return this._selectionModels.get(worksheetId);- }-setModels(selections: ISelectionModelValue[]) {const worksheetId = this.getWorksheetId();if (!worksheetId) {@@ -266,20 +269,12 @@ export class SelectionManager {this._selectionModels.set(worksheetId, models);}- getSelectionModelsValue(): ISelectionModelValue[] {- const models = this.getSelectionModels();- if (!models) {- return [];- }- const selectionModelsValue = [];- for (let model of models) {- selectionModelsValue.push(model.getValue());- }- return selectionModelsValue;- }-recreateControlsByRangeData() {}+ move(direction: Direction) {+ // const { startRow, startColumn, endColumn, endRow } = this.getCurrentModels();+ }+constructor(private _sheetView: SheetView) {this._plugin = this._sheetView.getPlugin() as SpreadsheetPlugin;this._initialize();diff --git a/packages/base-sheets/src/Model/Apply/SetSelectionValue.ts b/packages/base-sheets/src/Model/Apply/SetSelectionValue.tsindex c18d74c2e5..4f6d418bea 100644--- a/packages/base-sheets/src/Model/Apply/SetSelectionValue.ts+++ b/packages/base-sheets/src/Model/Apply/SetSelectionValue.ts@@ -17,7 +17,7 @@ export function SetSelectionValue(worksheet: Worksheet, selections: ISelectionMoif (!selectionManager) return [];- const result = selectionManager?.getSelectionModelsValue();+ const result = selectionManager?.getCurrentModelsValue();selectionManager.setModels(selections);