Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sheet): editor shortcuts #332

Merged
merged 42 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
911ac51
refactor(sheet): sheet selection and theme
DR-Univer Oct 24, 2023
a363c61
refactor(sheet): sheet selection and theme
DR-Univer Oct 24, 2023
262061b
fix(sheet): conflict
DR-Univer Oct 24, 2023
0c3ecc3
fix(sheet): import error
DR-Univer Oct 24, 2023
5d4113a
fix(sheet): import error
DR-Univer Oct 24, 2023
2794d64
fix(sheet): test error
DR-Univer Oct 24, 2023
7748137
feat(sheet): editor shortcuts
DR-Univer Oct 26, 2023
686541a
fix(ui-sheets): fix potential null subscription handling (#333)
jikkai Oct 27, 2023
5ead17e
chore: upgrade dependencies (#327)
jikkai Oct 27, 2023
bc362ae
feat: refactor `ColorPicker` (#329)
jikkai Oct 27, 2023
53907ad
fix(sheet): render refresh
DR-Univer Oct 27, 2023
6decc81
fix(sheet): code review fix
DR-Univer Oct 27, 2023
b6bbda4
refactor(sheet): sheet selection and theme
DR-Univer Oct 24, 2023
59b0f26
fix(sheet): import error
DR-Univer Oct 24, 2023
e51200b
feat(sheet): editor shortcuts
DR-Univer Oct 26, 2023
3710e69
fix(sheet): render refresh
DR-Univer Oct 27, 2023
ce6137f
fix(sheet): code review fix
DR-Univer Oct 27, 2023
b4c4719
fix(sheet): conflict
DR-Univer Oct 27, 2023
bba7631
fix(sheet): ts check
DR-Univer Oct 27, 2023
84d11d1
fix(sheet): test fix
DR-Univer Oct 27, 2023
c1685de
fix(sheet): expand method
DR-Univer Oct 27, 2023
6d41329
fix(sheet): expand error
DR-Univer Oct 27, 2023
5189c13
feat(design): create `design` repo for developing UI components (#335)
jikkai Oct 27, 2023
bc028b7
fix(sheet): type error
DR-Univer Oct 27, 2023
99a43bb
fix(sheet): uppercase letters
DR-Univer Oct 27, 2023
9e67e0a
refactor(sheet): sheet selection and theme
DR-Univer Oct 24, 2023
4ccd9fc
fix(sheet): import error
DR-Univer Oct 24, 2023
7a057da
feat(sheet): editor shortcuts
DR-Univer Oct 26, 2023
ee3219d
fix(sheet): render refresh
DR-Univer Oct 27, 2023
bf4ea52
fix(sheet): code review fix
DR-Univer Oct 27, 2023
058b724
refactor(sheet): sheet selection and theme
DR-Univer Oct 24, 2023
9f2baaa
refactor(sheet): sheet selection and theme
DR-Univer Oct 24, 2023
bfd66e8
fix(sheet): import error
DR-Univer Oct 24, 2023
6597a50
feat(sheet): editor shortcuts
DR-Univer Oct 26, 2023
c6a2cd6
fix(sheet): render refresh
DR-Univer Oct 27, 2023
8d3c79b
fix(sheet): code review fix
DR-Univer Oct 27, 2023
c5a2240
fix(sheet): ts check
DR-Univer Oct 27, 2023
9908a07
fix(sheet): test fix
DR-Univer Oct 27, 2023
fde0338
fix(sheet): expand method
DR-Univer Oct 27, 2023
d574ebf
fix(sheet): expand error
DR-Univer Oct 27, 2023
8735506
fix(sheet): type error
DR-Univer Oct 27, 2023
3a6bb62
fix(sheet): conflict
DR-Univer Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(sheet): render refresh
  • Loading branch information
DR-Univer committed Oct 27, 2023
commit ee3219d0d922616bca35de75a9f9ba09ee24749d
14 changes: 11 additions & 3 deletions packages/base-render/src/Component/Sheets/SheetSkeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ export class SpreadsheetSkeleton extends Skeleton {
}

const { mergeData } = this._config;

this._rowColumnSegment = this.getRowColumnSegment(bounds);
if (bounds != null) {
this._rowColumnSegment = this.getRowColumnSegment(bounds);
}
this._dataMergeCache = mergeData && this._getMergeCells(mergeData, this._rowColumnSegment);
this._calculateStylesCache();
// this._overflowCache = this._calculateOverflowCache();
Expand Down Expand Up @@ -822,7 +823,14 @@ export class SpreadsheetSkeleton extends Skeleton {
return rowHeightAccumulation[lastRowIndex] + columnHeaderHeightAndMarginTop;
}

getCellByIndex(row: number, column: number, scaleX: number, scaleY: number) {
/**
* Return cell information corresponding to the current coordinates, including the merged cell object.
* @param row Specified Row Coordinate
* @param column Specified Column Coordinate
* @param scaleX render scene scale x-axis, current Horizontal Scale, scene.getAncestorScale
* @param scaleY render scene scale y-axis, current Vertical Scale, scene.getAncestorScale
*/
getCellByIndex(row: number, column: number, scaleX: number, scaleY: number): ISelectionCellWithCoord {
const {
rowHeightAccumulation,
columnWidthAccumulation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export const COMMAND_LISTENER_SKELETON_CHANGE = [
AddWorksheetMergeMutation.id,
RemoveWorksheetMergeMutation.id,
MoveRowsMutation.id,
SetRangeValuesMutation.id,
SetBorderStylesMutation.id,
SetColHiddenMutation.id,
SetColVisibleMutation.id,
SetRowHiddenMutation.id,
SetRowVisibleMutation.id,
];

export const COMMAND_LISTENER_VALUE_CHANGE = [SetBorderStylesMutation.id, SetRangeValuesMutation.id];
15 changes: 15 additions & 0 deletions packages/base-sheets/src/Basics/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ export function getNormalSelectionStyle(themeService: ThemeService): ISelectionS
};
}

/**
* Process a selection with coordinates and style,
* and extract the coordinate information, because the render needs coordinates when drawing.
* Since the selection.manager.service is unrelated to the coordinates,
* it only accepts data of type ISelectionWithStyle, so a conversion is necessary.
* @param selectionWithCoordAndStyle Selection with coordinates and style
* @returns
*/
export function convertSelectionDataToRange(
selectionWithCoordAndStyle: ISelectionWithCoordAndStyle
): ISelectionWithStyle {
Expand Down Expand Up @@ -137,6 +145,13 @@ export function convertSelectionDataToRange(
return result;
}

/**
* Convert the coordinates of a single cell into a selection data.
* @param row Specified Row Coordinate
* @param column Specified Column Coordinate
* @param mergeData Obtain the data of merged cells through the worksheet object.
* @returns ISelectionWithStyle
*/
export function transformCellDataToSelectionData(
row: number,
column: number,
Expand Down
13 changes: 7 additions & 6 deletions packages/base-sheets/src/Controller/sheet-render.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,11 @@ export class SheetRenderController extends Disposable {
}

private _commandExecutedListener() {
const updateCommandList = COMMAND_LISTENER_SKELETON_CHANGE;

this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (updateCommandList.includes(command.id)) {
const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const unitId = workbook.getUnitId();
const workbook = this._currentUniverService.getCurrentUniverSheetInstance();
const unitId = workbook.getUnitId();
if (COMMAND_LISTENER_SKELETON_CHANGE.includes(command.id)) {
const worksheet = workbook.getActiveSheet();
const sheetId = worksheet.getSheetId();
const params = command.params;
Expand All @@ -123,8 +121,11 @@ export class SheetRenderController extends Disposable {
commandId: command.id,
});
}
// else if (COMMAND_LISTENER_VALUE_CHANGE.includes(command.id)) {
// this._sheetSkeletonManagerService.reCalculate();
// }

this._renderManagerService.getCurrent()?.mainComponent?.makeDirty(); // refresh spreadsheet
this._renderManagerService.getRenderById(unitId)?.mainComponent?.makeDirty(); // refresh spreadsheet
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ import {

// TODO@wzhudev: we also need to handle when the current selection is the whole spreadsheet, whole rows or whole columns

// TODO@DR-UNIVER: moveStepPage and moveStepEnd implement
export enum JumpOver {
moveStopeOne,
moveGap,
moveStepPage,
moveStepEnd,
}

export interface IMoveSelectionCommandParams {
direction: Direction;
jumpOver?: boolean;
jumpOver?: JumpOver;
nextStep?: number;
}

/**
Expand All @@ -61,9 +70,10 @@ export const MoveSelectionCommand: ICommand<IMoveSelectionCommandParams> = {
const startRange = getStartRange(range, primary, direction);

// the start range is from the primary selection range
const next = jumpOver
? findNextGapRange(startRange, direction, worksheet)
: findNextRange(startRange, direction, worksheet);
const next =
jumpOver === JumpOver.moveGap
? findNextGapRange(startRange, direction, worksheet)
: findNextRange(startRange, direction, worksheet);
const destRange = getCellAtRowCol(next.startRow, next.startColumn, worksheet);

if (Rectangle.equals(destRange, startRange)) {
Expand Down Expand Up @@ -140,6 +150,7 @@ export const MoveSelectionEnterAndTabCommand: ICommand<IMoveSelectionEnterAndTab
let resultRange;
const { startRow, endRow, startColumn, endColumn } = range;
if (startRow < endRow || startColumn < endColumn) {
// Handle the situation of moving the active cell within the selection area.
shortcutExperienceService.remove({
unitId,
sheetId,
Expand Down Expand Up @@ -182,6 +193,7 @@ export const MoveSelectionEnterAndTabCommand: ICommand<IMoveSelectionEnterAndTab
},
};
} else {
// Handle the regular situation of moving the selection area.
if (keycode === KeyCode.TAB) {
if (shortcutExperienceParam == null) {
shortcutExperienceService.addOrUpdate({
Expand Down Expand Up @@ -241,8 +253,8 @@ export const MoveSelectionEnterAndTabCommand: ICommand<IMoveSelectionEnterAndTab

export interface IExpandSelectionCommandParams {
direction: Direction;

jumpOver?: boolean;
jumpOver?: JumpOver;
nextStep?: number;
}

// Though the command's name is "expand-selection", it actually does not expand but shrink the selection.
Expand All @@ -269,10 +281,10 @@ export const ExpandSelectionCommand: ICommand<IExpandSelectionCommandParams> = {
const isShrink = checkIfShrink(selection, direction, currentWorksheet);

const destRange = !isShrink
? jumpOver
? jumpOver === JumpOver.moveGap
? expandToNextGapRange(startRange, direction, currentWorksheet)
: expandToNextCell(startRange, direction, currentWorksheet)
: jumpOver
: jumpOver === JumpOver.moveGap
? shrinkToNextGapRange(
startRange,
// TODO: should fix on SelectionManagerService's side
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export function findNextRange(
direction: Direction,
worksheet: Worksheet,
boundary?: IRange,
isFindNext: boolean = true
isFindNext: boolean = true,
nextStep: number = 1
): IRange {
let destRange: IRange = { ...startRange };

Expand All @@ -82,7 +83,7 @@ export function findNextRange(
let next: number;
switch (direction) {
case Direction.UP:
next = startRange.startRow - 1;
next = startRange.startRow - nextStep;
while (next > -1 && !worksheet.getRowVisible(next)) {
next -= 1;
}
Expand All @@ -99,7 +100,7 @@ export function findNextRange(
}
break;
case Direction.DOWN:
next = startRange.endRow + 1;
next = startRange.endRow + nextStep;
while (next < worksheet.getRowCount() && !worksheet.getRowVisible(next)) {
next += 1;
}
Expand All @@ -116,7 +117,7 @@ export function findNextRange(
}
break;
case Direction.LEFT:
next = startRange.startColumn - 1;
next = startRange.startColumn - nextStep;
while (next > -1 && !worksheet.getColVisible(next)) {
next -= 1;
}
Expand All @@ -133,7 +134,7 @@ export function findNextRange(
}
break;
case Direction.RIGHT:
next = startRange.endColumn + 1;
next = startRange.endColumn + nextStep;
while (next < worksheet.getColumnCount() && !worksheet.getColVisible(next)) {
next += 1;
}
Expand Down
1 change: 1 addition & 0 deletions packages/base-sheets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export type {
export {
ExpandSelectionCommand,
type IMoveSelectionEnterAndTabCommandParams,
JumpOver,
MoveSelectionCommand,
MoveSelectionEnterAndTabCommand,
SelectAllCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ export class SheetSkeletonManagerService implements IDisposable {
setCurrent(searchParam: ISheetSkeletonManagerSearch): Nullable<ISheetSkeletonManagerParam> {
const param = this._getCurrentBySearch(searchParam);
if (param != null) {
if (param.dirty) {
param.skeleton.makeDirty(true);
param.dirty = false;
}
param.skeleton.calculate();
this._reCalculate(param);
} else {
const { unitId, sheetId } = searchParam;

Expand Down Expand Up @@ -98,6 +94,22 @@ export class SheetSkeletonManagerService implements IDisposable {
return this.getCurrent();
}

reCalculate() {
const param = this.getCurrent();
if (param == null) {
return;
}
this._reCalculate(param);
}

private _reCalculate(param: ISheetSkeletonManagerParam) {
if (param.dirty) {
param.skeleton.makeDirty(true);
param.dirty = false;
}
param.skeleton.calculate();
}

makeDirtyCurrent(state: boolean = true) {
this.makeDirty(this._currentSkeleton, state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class SharedController extends Disposable {
@ICommandService private readonly _commandService: ICommandService
) {
super();

this.initialize();
}

initialize(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ import {
EditorDeleteLeftShortcutInActive,
generateArrowSelectionShortCuItem,
} from './shortcuts/editor.shortcut';
import {
SetColHiddenShortcutItem,
SetRedoShortcutItem,
SetRowHiddenShortcutItem,
SetUndoShortcutItem,
} from './shortcuts/operation.shortcut';
import { SetColHiddenShortcutItem, SetRowHiddenShortcutItem } from './shortcuts/operation.shortcut';
import {
ExpandSelectionDownShortcutItem,
ExpandSelectionEndDownShortcutItem,
Expand Down Expand Up @@ -320,8 +315,6 @@ export class SheetUIController extends Disposable {
EditorCursorEscShortcut,

// operation shortcuts
SetUndoShortcutItem,
SetRedoShortcutItem,
SetRowHiddenShortcutItem,
SetColHiddenShortcutItem,
].forEach((item) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import { SetColHiddenCommand, SetRowHiddenCommand } from '@univerjs/base-sheets';
import { IShortcutItem, KeyCode, MetaKeys } from '@univerjs/base-ui';
import { RedoCommand, UndoCommand } from '@univerjs/core';

import { whenEditorNotActivated } from './utils';

export const SetUndoShortcutItem: IShortcutItem = {
id: UndoCommand.id,
// when focusing on any other input tag do not trigger this shortcut
preconditions: (contextService) => whenEditorNotActivated(contextService),
binding: KeyCode.Z | MetaKeys.CTRL_COMMAND,
};
// export const SetUndoShortcutItem: IShortcutItem = {
// id: UndoCommand.id,
// // when focusing on any other input tag do not trigger this shortcut
// preconditions: (contextService) => whenEditorNotActivated(contextService),
// binding: KeyCode.Z | MetaKeys.CTRL_COMMAND,
// };

export const SetRedoShortcutItem: IShortcutItem = {
id: RedoCommand.id,
// when focusing on any other input tag do not trigger this shortcut
preconditions: (contextService) => whenEditorNotActivated(contextService),
binding: KeyCode.Y | MetaKeys.CTRL_COMMAND,
};
// export const SetRedoShortcutItem: IShortcutItem = {
// id: RedoCommand.id,
// // when focusing on any other input tag do not trigger this shortcut
// preconditions: (contextService) => whenEditorNotActivated(contextService),
// binding: KeyCode.Y | MetaKeys.CTRL_COMMAND,
// };

export const SetRowHiddenShortcutItem: IShortcutItem = {
id: SetRowHiddenCommand.id,
Expand Down
Loading