Skip to content

Commit

Permalink
chore: better code
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Dec 16, 2024
1 parent 316aa6a commit db884f7
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ export class SpreadsheetSkeleton extends Skeleton {
return this._visibleRange;
}

/**
* Get range needs to render.
* @param viewportKey
* @returns
*/
visibleRangeByViewportKey(viewportKey: SHEET_VIEWPORT_KEY): Nullable<IRowColumnRange> {
return this._cacheRangeMap.get(viewportKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export class PromptController extends Disposable {
const d = new DisposableCollection();

// response events from selection control, when selection control is created
// this is so weird !!!
// this is so weird !!! why didn't selection control handle move event itself ???

this.disposeWithMe(merge(this._refSelectionsService.selectionSet$, this._refSelectionsService.selectionMoveEnd$).subscribe((selections) => {
d.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export interface IScrollToCellCommandParams {
}

/**
* Scroll to make the range at top left edge of viewport.
* The command is used to scroll to the specific cell if the target cell is not in the viewport.
*/
export const ScrollToCellCommand: ICommand<IScrollToCellCommandParams> = {
id: 'sheet.command.scroll-to-cell',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ export class SheetsScrollRenderController extends Disposable implements IRenderM
this._wheelEventListener();
this._scrollBarEventListener();
this._initSkeletonListener();

window.src = this;
}

private _wheelEventListener() {
Expand Down Expand Up @@ -472,7 +470,7 @@ export class SheetsScrollRenderController extends Disposable implements IRenderM
return skeleton.getRangeByViewBound(vpInfo.viewBound);
}

// why so complicated? scrollToCell do the same thing
// why so complicated? ScrollRenderController@scrollToCell do the same thing, including the scenario of freezing.
// eslint-disable-next-line max-lines-per-function, complexity
private _scrollToCell(row: number, column: number, forceTop?: boolean, forceLeft?: boolean): boolean {
const { rowHeightAccumulation, columnWidthAccumulation } = this._sheetSkeletonManagerService.getCurrent()?.skeleton ?? {};
Expand Down
7 changes: 3 additions & 4 deletions packages/sheets-ui/src/facade/f-workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

import type { awaitTime, ICommandService, type IDisposable, ILogService, Nullable, toDisposable } from '@univerjs/core';
import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui';
import type { IHoverRichTextInfo, IHoverRichTextPosition } from '../services/hover-manager.service';
import type { IScrollState } from '../services/scroll-manager.service';
import type { IDisposable, Nullable } from '@univerjs/core';
import { awaitTime, ICommandService, ILogService, toDisposable } from '@univerjs/core';
import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';
import type { IEditorBridgeServiceVisibleParam, IHoverRichTextInfo, IHoverRichTextPosition, IScrollState } from '@univerjs/sheets-ui';
import { HoverManagerService, SetCellEditVisibleOperation, SheetScrollManagerService } from '@univerjs/sheets-ui';
import { FWorkbook } from '@univerjs/sheets/facade';
import { type IDialogPartMethodOptions, IDialogService, type ISidebarMethodOptions, ISidebarService, KeyCode } from '@univerjs/ui';
Expand Down
11 changes: 4 additions & 7 deletions packages/sheets-ui/src/facade/f-worksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@

import type { IDisposable, IRange, Nullable } from '@univerjs/core';
import type { RenderManagerService } from '@univerjs/engine-render';
import type { IScrollState, IViewportScrollState } from '../services/scroll-manager.service';
import type { IScrollState, IViewportScrollState } from '@univerjs/sheets-ui';
import { ICommandService, toDisposable } from '@univerjs/core';
import { IRenderManagerService, SHEET_VIEWPORT_KEY, sheetContentViewportKeys } from '@univerjs/engine-render';
import { ChangeZoomRatioCommand, SheetScrollManagerService, SheetSkeletonManagerService, SheetsScrollRenderController } from '@univerjs/sheets-ui';
import { FWorksheet } from '@univerjs/sheets/facade';
import { ChangeZoomRatioCommand } from '../commands/commands/set-zoom-ratio.command';
import { SheetsScrollRenderController } from '../controllers/render-controllers/scroll.render-controller';
import { SheetScrollManagerService } from '../services/scroll-manager.service';
import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';

export interface IFWorksheetSkeletonMixin {
/**
Expand Down Expand Up @@ -93,7 +90,7 @@ export class FWorksheetSkeletonMixin extends FWorksheet implements IFWorksheetSk
}

/**
* Return visible range.
* Return visible range, sum view range of 4 viewports.
* @returns IRange
*/
getVisibleRange(): IRange {
Expand Down Expand Up @@ -160,7 +157,7 @@ export class FWorksheetSkeletonMixin extends FWorksheet implements IFWorksheetSk

/**
* Invoked when scrolling the sheet.
* @param callback
* @param {function(params: Nullable<IViewportScrollState>): void} callback The scrolling callback function,

Check failure on line 160 in packages/sheets-ui/src/facade/f-worksheet.ts

View workflow job for this annotation

GitHub Actions / eslint

Trailing spaces not allowed
* @example
* ``` ts
* univerAPI.getActiveWorkbook().getActiveSheet().onScroll((params) => {...})
Expand Down
Loading

0 comments on commit db884f7

Please sign in to comment.