@univerjs/sheets v0.5.4


Class: FSelection

Defined in: submodules/univer/packages/sheets/src/facade/f-selection.ts:37

Description

Represents the active selection in the sheet.

Example

const fWorkbook = univerAPI.getActiveWorkbook()
const fWorksheet = fWorkbook.getActiveSheet()
const fSelection = fWorksheet.getSelection();
const activeRange = fSelection.getActiveRange();
console.log(activeRange);

Constructors

new FSelection()

new FSelection(
   _workbook, 
   _worksheet, 
   _selections, 
   _injector): FSelection

Defined in: submodules/univer/packages/sheets/src/facade/f-selection.ts:38

Parameters

ParameterType
_workbookWorkbook
_worksheetWorksheet
_selectionsreadonly ISelectionWithStyle[]
_injectorInjector

Returns

FSelection

Methods

getActiveRange()

getActiveRange(): null | FRange

Defined in: submodules/univer/packages/sheets/src/facade/f-selection.ts:51

Represents the active selection in the sheet. Which means the selection contains the active cell.

Returns

null | FRange

The active selection.


getActiveRangeList()

getActiveRangeList(): FRange[]

Defined in: submodules/univer/packages/sheets/src/facade/f-selection.ts:64

Represents the active selection list in the sheet.

Returns

FRange[]

The active selection list.


getActiveSheet()

getActiveSheet(): FWorksheet

Defined in: submodules/univer/packages/sheets/src/facade/f-selection.ts:95

Returns the active sheet in the spreadsheet.

Returns

FWorksheet

The active sheet in the spreadsheet.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fSelection = fWorksheet.getSelection();
const activeSheet = fSelection.getActiveSheet();
console.log(activeSheet.equalTo(fWorksheet)); // true

getCurrentCell()

getCurrentCell(): Nullable<ISelectionCell>

Defined in: submodules/univer/packages/sheets/src/facade/f-selection.ts:74

Represents the current select cell in the sheet.

Returns

Nullable<ISelectionCell>

The current select cell info.Pay attention to the type of the return value.


getNextDataRange()

getNextDataRange(direction): null | FRange

Defined in: submodules/univer/packages/sheets/src/facade/f-selection.ts:169

Get the next primary cell in the specified direction. If the primary cell not exists in selections, return null.

Parameters

ParameterTypeDescription
directionDirectionThe direction to move the primary cell.The enum value is maybe one of the following: UP(0),RIGHT(1), DOWN(2), LEFT(3).

Returns

null | FRange

The next primary cell in the specified direction.

Example

// import { Direction } from '@univerjs/core';
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
// make sure the active cell is A1 and selection is A1:C3
const fSelection = fWorksheet.getSelection();
const nextCell = fSelection.getNextDataRange(Direction.RIGHT);
console.log(nextCell?.getA1Notation()); // B1

updatePrimaryCell()

updatePrimaryCell(cell): FSelection

Defined in: submodules/univer/packages/sheets/src/facade/f-selection.ts:114

Update the primary cell in the selection. if the primary cell not exists in selections, add it to the selections and clear the old selections.

Parameters

ParameterTypeDescription
cellFRangeThe new primary cell to update.

Returns

FSelection

The new selection after updating the primary cell.Because the selection is immutable, the return value is a new selection.

Example

const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
const fSelection = fWorksheet.getSelection();
const cell = fWorksheet.getCell('A1');
const newSelection = fSelection.updatePrimaryCell(cell);
console.log(newSelection.getActiveRange().getA1Notation()); // A1