Skip to content

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.

fix: scroll cmd for pointer down at scrolltrack (#3429)

lumix8e9f513a8a63
diff --git a/packages/engine-render/src/shape/base-scroll-bar.ts b/packages/engine-render/src/shape/base-scroll-bar.ts
index be044ba46b..ef78b4f5d0 100644
--- a/packages/engine-render/src/shape/base-scroll-bar.ts
+++ b/packages/engine-render/src/shape/base-scroll-bar.ts
@@ -55,11 +55,11 @@ export abstract class BaseScrollBar extends Disposable {
verticalMinusMiniThumb: number = 0;
- horizonBarRect: Nullable<Rect>;
+ horizonScrollTrack: Nullable<Rect>;
horizonThumbRect: Nullable<Rect>;
- verticalBarRect: Nullable<Rect>;
+ verticalScrollTrack: Nullable<Rect>;
verticalThumbRect: Nullable<Rect>;
@@ -160,27 +160,27 @@ export abstract class BaseScrollBar extends Disposable {
return this.verticalThumbRect;
}
- if (this.horizonBarRect?.isHit(coord)) {
- return this.horizonBarRect;
+ if (this.horizonScrollTrack?.isHit(coord)) {
+ return this.horizonScrollTrack;
}
- if (this.verticalBarRect?.isHit(coord)) {
- return this.verticalBarRect;
+ if (this.verticalScrollTrack?.isHit(coord)) {
+ return this.verticalScrollTrack;
}
return null;
}
override dispose() {
- this.horizonBarRect?.dispose();
+ this.horizonScrollTrack?.dispose();
this.horizonThumbRect?.dispose();
- this.verticalBarRect?.dispose();
+ this.verticalScrollTrack?.dispose();
this.verticalThumbRect?.dispose();
this.placeholderBarRect?.dispose();
- this.horizonBarRect = null;
+ this.horizonScrollTrack = null;
this.horizonThumbRect = null;
- this.verticalBarRect = null;
+ this.verticalScrollTrack = null;
this.verticalThumbRect = null;
this.placeholderBarRect = null;
}
diff --git a/packages/engine-render/src/shape/scroll-bar.ts b/packages/engine-render/src/shape/scroll-bar.ts
index 1588121746..807652bf9a 100644
--- a/packages/engine-render/src/shape/scroll-bar.ts
+++ b/packages/engine-render/src/shape/scroll-bar.ts
@@ -14,23 +14,23 @@
* limitations under the License.
*/
-import type { EventState, IKeyValue, Nullable } from '@univerjs/core';
-
import { Subscription } from 'rxjs';
-import type { IMouseEvent, IPointerEvent } from '../basics/i-events';
+
+import type { EventState, IKeyValue, Nullable } from '@univerjs/core';
import { Transform } from '../basics/transform';
+import { BaseScrollBar } from './base-scroll-bar';
+import { Rect } from './rect';
+import type { IMouseEvent, IPointerEvent } from '../basics/i-events';
import type { Vector2 } from '../basics/vector2';
import type { UniverRenderingContext } from '../context';
import type { ThinScene } from '../thin-scene';
import type { Viewport } from '../viewport';
import type { IScrollBarProps } from './base-scroll-bar';
-import { BaseScrollBar } from './base-scroll-bar';
-import { Rect } from './rect';
const MINI_THUMB_SIZE = 17;
export class ScrollBar extends BaseScrollBar {
- protected _view!: Viewport;
+ protected _viewport!: Viewport;
private _mainScene: Nullable<ThinScene>;
@@ -79,11 +79,11 @@ export class ScrollBar extends BaseScrollBar {
console.warn('Missing viewport');
}
this.setProps(props);
- this._view = view;
+ this._viewport = view;
this._initialScrollRect();
this._initialVerticalEvent();
this._initialHorizontalEvent();
- this._view.setScrollBar(this);
+ this._viewport.setScrollBar(this);
}
static attachTo(view: Viewport, props?: IScrollBarProps) {
@@ -98,22 +98,22 @@ export class ScrollBar extends BaseScrollBar {
this._verticalPointerUpSub?.unsubscribe();
this._eventSub.unsubscribe();
this._mainScene = null;
- this._view.removeScrollBar();
+ this._viewport.removeScrollBar();
}
override render(ctx: UniverRenderingContext, left: number = 0, top: number = 0) {
- const { scrollX, scrollY } = this._view;
+ const { scrollX, scrollY } = this._viewport;
ctx.save();
const transform = new Transform([1, 0, 0, 1, left, top]);
const m = transform.getMatrix();
ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
if (this.enableHorizontal) {
- this.horizonBarRect!.render(ctx);
+ this.horizonScrollTrack!.render(ctx);
this.horizonThumbRect!.translate(scrollX).render(ctx);
}
if (this.enableVertical) {
- this.verticalBarRect!.render(ctx);
+ this.verticalScrollTrack!.render(ctx);
this.verticalThumbRect!.translate(undefined, scrollY).render(ctx);
}
@@ -149,9 +149,9 @@ export class ScrollBar extends BaseScrollBar {
}
override makeDirty(state: boolean) {
- this.horizonBarRect?.makeDirty(state);
+ this.horizonScrollTrack?.makeDirty(state);
this.horizonThumbRect?.makeDirty(state);
- this.verticalBarRect?.makeDirty(state);
+ this.verticalScrollTrack?.makeDirty(state);
this.verticalThumbRect?.makeDirty(state);
this.placeholderBarRect?.makeDirty(state);
@@ -159,7 +159,7 @@ export class ScrollBar extends BaseScrollBar {
}
makeViewDirty(state: boolean) {
- const mainScene = this._mainScene || this._view.scene;
+ const mainScene = this._mainScene || this._viewport.scene;
mainScene.makeDirty(state);
}
@@ -172,12 +172,12 @@ export class ScrollBar extends BaseScrollBar {
return this.verticalThumbRect;
}
- if (this.horizonBarRect?.isHit(coord)) {
- return this.horizonBarRect;
+ if (this.horizonScrollTrack?.isHit(coord)) {
+ return this.horizonScrollTrack;
}
- if (this.verticalBarRect?.isHit(coord)) {
- return this.verticalBarRect;
+ if (this.verticalScrollTrack?.isHit(coord)) {
+ return this.verticalScrollTrack;
}
return null;
@@ -218,7 +218,7 @@ export class ScrollBar extends BaseScrollBar {
this.horizontalThumbWidth = MINI_THUMB_SIZE;
}
- this.horizonBarRect?.transformByState({
+ this.horizonScrollTrack?.transformByState({
left: 0,
top: parentHeight - this.barSize,
width: this.horizontalBarWidth,
@@ -237,7 +237,7 @@ export class ScrollBar extends BaseScrollBar {
}
this.horizonThumbRect?.transformByState({
- left: this._view.scrollX,
+ left: this._viewport.scrollX,
top: parentHeight - this.barSize + this.thumbMargin,
width: this.horizontalThumbWidth,
height: this.barSize - this.thumbMargin * 2,
@@ -260,7 +260,7 @@ export class ScrollBar extends BaseScrollBar {
this.verticalThumbHeight = MINI_THUMB_SIZE;
}
- this.verticalBarRect?.transformByState({
+ this.verticalScrollTrack?.transformByState({
left: parentWidth - this.barSize,
top: 0,
width: this.barSize - this.barBorder,
@@ -280,7 +280,7 @@ export class ScrollBar extends BaseScrollBar {
this.verticalThumbRect?.transformByState({
left: parentWidth - this.barSize + this.thumbMargin,
- top: this._view.scrollY,
+ top: this._viewport.scrollY,
width: this.barSize - this.thumbMargin * 2,
height: this.verticalThumbHeight,
});
@@ -289,7 +289,7 @@ export class ScrollBar extends BaseScrollBar {
private _initialScrollRect() {
if (this.enableHorizontal) {
- this.horizonBarRect = new Rect('__horizonBarRect__', {
+ this.horizonScrollTrack = new Rect('__horizonBarRect__', {
fill: this.barBackgroundColor!,
strokeWidth: this.barBorder,
stroke: this.barBorderColor!,
@@ -302,7 +302,7 @@ export class ScrollBar extends BaseScrollBar {
}
if (this.enableVertical) {
- this.verticalBarRect = new Rect('__verticalBarRect__', {
+ this.verticalScrollTrack = new Rect('__verticalBarRect__', {
fill: this.barBackgroundColor!,
strokeWidth: this.barBorder,
stroke: this.barBorderColor!,
@@ -328,55 +328,56 @@ export class ScrollBar extends BaseScrollBar {
return;
}
- const mainScene = this._mainScene || this._view.scene;
+ const mainScene = this._mainScene || this._viewport.scene;
- // this.verticalThumbRect?.on(
- // EVENT_TYPE.PointerEnter,
- // this._hoverFunc(this.thumbHoverBackgroundColor!, this.verticalThumbRect)
- // );
- // this.verticalThumbRect?.on(
- // EVENT_TYPE.PointerLeave,
- // this._hoverFunc(this.thumbBackgroundColor!, this.verticalThumbRect)
- // );
- this.verticalThumbRect && this._eventSub.add(this.verticalThumbRect.onPointerEnter$.subscribeEvent((_evt: unknown, _state: EventState) => {
- this._hoverFunc(this.thumbHoverBackgroundColor!, this.verticalThumbRect!);
- }));
- this.verticalThumbRect && this._eventSub.add(this.verticalThumbRect.onPointerLeave$.subscribeEvent((_evt: unknown, _state: EventState) => {
- this._hoverFunc(this.thumbHoverBackgroundColor!, this.verticalThumbRect!);
- }));
-
- this.verticalBarRect && this._eventSub.add(this.verticalBarRect.onPointerDown$.subscribeEvent((evt: unknown, state: EventState) => {
- const e = evt as IPointerEvent | IMouseEvent;
- this._view.scrollToBarPos({
- y: e.offsetY - this._view.top - this.verticalThumbHeight / 2,
- });
- state.stopPropagation();
- }));
+ if (this.verticalThumbRect) {
+ this._eventSub.add(this.verticalThumbRect.onPointerEnter$.subscribeEvent((_evt: unknown, _state: EventState) => {
+ this._hoverFunc(this.thumbHoverBackgroundColor!, this.verticalThumbRect!);
+ }));
+ }
+ if (this.verticalThumbRect) {
+ this._eventSub.add(this.verticalThumbRect.onPointerLeave$.subscribeEvent((_evt: unknown, _state: EventState) => {
+ this._hoverFunc(this.thumbHoverBackgroundColor!, this.verticalThumbRect!);
+ }));
+ }
- // 垂直滚动条的拖拽事件
- // scene.input-manager@_onPointerDown --> base-object@triggerPointerDown!
- this.verticalThumbRect && this._eventSub.add(this.verticalThumbRect.onPointerDown$.subscribeEvent((evt: unknown, state: EventState) => {
- const e = evt as IPointerEvent | IMouseEvent;
- const srcElement = this.verticalThumbRect;
- this._isVerticalMove = true;
- this._lastX = e.offsetX;
- this._lastY = e.offsetY;
- // srcElement.fill = this._thumbHoverBackgroundColor!;
- srcElement?.setProps({
- fill: this.thumbActiveBackgroundColor!,
- });
- mainScene.disableObjectsEvent();
- this.makeViewDirty(true);
- state.stopPropagation();
- }));
+ // events for pointerdown at scrolltrack
+ if (this.verticalScrollTrack) {
+ this._eventSub.add(this.verticalScrollTrack.onPointerDown$.subscribeEvent((evt: unknown, state: EventState) => {
+ const e = evt as IPointerEvent | IMouseEvent;
+ this._viewport.scrollToBarPos({
+ y: e.offsetY - this._viewport.top - this.verticalThumbHeight / 2,
+ });
+ state.stopPropagation();
+ }));
+ }
+
+ // drag events for vertical scrollbar
+ // scene.input-manager@_onPointerDown --> base-object@triggerPointerDown!
+ if (this.verticalThumbRect) {
+ this._eventSub.add(this.verticalThumbRect.onPointerDown$.subscribeEvent((evt: unknown, state: EventState) => {
+ const e = evt as IPointerEvent | IMouseEvent;
+ const srcElement = this.verticalThumbRect;
+ this._isVerticalMove = true;
+ this._lastX = e.offsetX;
+ this._lastY = e.offsetY;
+ // srcElement.fill = this._thumbHoverBackgroundColor!;
+ srcElement?.setProps({
+ fill: this.thumbActiveBackgroundColor!,
+ });
+ mainScene.disableObjectsEvent();
+ this.makeViewDirty(true);
+ state.stopPropagation();
+ }));
+ }
this._verticalPointerMoveSub = mainScene.onPointerMove$.subscribeEvent((evt: unknown, _state: EventState) => {
const e = evt as IPointerEvent | IMouseEvent;
if (!this._isVerticalMove) {
return;
}
- this._view.scrollByBar({
- y: e.offsetY - this._lastY,
+ this._viewport.scrollToBarPos({
+ y: e.offsetY,
});
this._lastY = e.offsetY;
@@ -418,7 +419,7 @@ export class ScrollBar extends BaseScrollBar {
return;
}
- const mainScene = this._mainScene || this._view.scene;
+ const mainScene = this._mainScene || this._viewport.scene;
// this.horizonThumbRect?.on(
// EVENT_TYPE.PointerEnter,
@@ -428,44 +429,50 @@ export class ScrollBar extends BaseScrollBar {
// EVENT_TYPE.PointerLeave,
// this._hoverFunc(this.thumbBackgroundColor!, this.horizonThumbRect)
// );
- this.horizonThumbRect && this._eventSub.add(this.horizonThumbRect.onPointerEnter$.subscribeEvent((_evt: unknown, _state: EventState) => {
- this._hoverFunc(this.thumbHoverBackgroundColor!, this.horizonThumbRect!);
- }));
- this.horizonThumbRect && this._eventSub.add(this.horizonThumbRect.onPointerLeave$.subscribeEvent((_evt: unknown, _state: EventState) => {
- this._hoverFunc(this.thumbHoverBackgroundColor!, this.horizonThumbRect!);
- }));
-
- // 水平滚动条槽的点击滚动事件
- this.horizonBarRect && this._eventSub.add(this.horizonBarRect.onPointerDown$.subscribeEvent((evt: unknown, state: EventState) => {
- const e = evt as IPointerEvent | IMouseEvent;
- this._view.scrollToBarPos({
- x: e.offsetX - this._view.left - this.horizontalThumbWidth / 2,
- });
- state.stopPropagation();
- }));
+ if (this.horizonThumbRect) {
+ this._eventSub.add(this.horizonThumbRect.onPointerEnter$.subscribeEvent((_evt: unknown, _state: EventState) => {
+ this._hoverFunc(this.thumbHoverBackgroundColor!, this.horizonThumbRect!);
+ }));
+ }
+ if (this.horizonThumbRect) {
+ this._eventSub.add(this.horizonThumbRect.onPointerLeave$.subscribeEvent((_evt: unknown, _state: EventState) => {
+ this._hoverFunc(this.thumbHoverBackgroundColor!, this.horizonThumbRect!);
+ }));
+ }
+ if (this.horizonScrollTrack) {
+ this._eventSub.add(this.horizonScrollTrack.onPointerDown$.subscribeEvent((evt: unknown, state: EventState) => {
+ const e = evt as IPointerEvent | IMouseEvent;
+ this._viewport.scrollToBarPos({
+ x: e.offsetX - this._viewport.left - this.horizontalThumbWidth / 2,
+ });
+ state.stopPropagation();
+ }));
+ }
- // 水平滚动条的拖拽事件
- this.horizonThumbRect && this._eventSub.add(this.horizonThumbRect.onPointerDown$.subscribeEvent((evt: unknown, state: EventState) => {
- const e = evt as IPointerEvent | IMouseEvent;
- this._isHorizonMove = true;
- this._lastX = e.offsetX;
- this._lastY = e.offsetY;
+ // drag and move event
+ if (this.horizonThumbRect) {
+ this._eventSub.add(this.horizonThumbRect.onPointerDown$.subscribeEvent((evt: unknown, state: EventState) => {
+ const e = evt as IPointerEvent | IMouseEvent;
+ this._isHorizonMove = true;
+ this._lastX = e.offsetX;
+ this._lastY = e.offsetY;
// this.fill = this._thumbHoverBackgroundColor!;
- this.horizonThumbRect?.setProps({
- fill: this.thumbActiveBackgroundColor!,
- });
- this.makeViewDirty(true);
- mainScene.disableObjectsEvent();
- state.stopPropagation();
- }));
+ this.horizonThumbRect?.setProps({
+ fill: this.thumbActiveBackgroundColor!,
+ });
+ this.makeViewDirty(true);
+ mainScene.disableObjectsEvent();
+ state.stopPropagation();
+ }));
+ }
this._horizonPointerMoveSub = mainScene.onPointerMove$.subscribeEvent((evt: unknown, _state: EventState) => {
const e = evt as IPointerEvent | IMouseEvent;
if (!this._isHorizonMove) {
return;
}
- this._view.scrollByBar({
- x: e.offsetX - this._lastX,
+ this._viewport.scrollToBarPos({
+ x: e.offsetX,
});
this._lastX = e.offsetX;
mainScene.getEngine()?.setRemainCapture();
diff --git a/packages/engine-render/src/viewport.ts b/packages/engine-render/src/viewport.ts
index eebc0bdef9..752b356093 100644
--- a/packages/engine-render/src/viewport.ts
+++ b/packages/engine-render/src/viewport.ts
@@ -128,7 +128,7 @@ export class Viewport {
onScrollAfter$ = new EventSubject<IScrollObserverParam>();
- onScrollBefore$ = new EventSubject<IScrollObserverParam>();
+ // onScrollBefore$ = new EventSubject<IScrollObserverParam>();
onScrollEnd$ = new EventSubject<IScrollObserverParam>();
@@ -373,8 +373,8 @@ export class Viewport {
set height(height: Nullable<number>) {
const maxHeight = this.scene.getParent().height;
- if (height !== null && height !== undefined) {
- this._height = Tools.clamp(height, 0, maxHeight);
+ if (Tools.isDefine(height)) {
+ this._height = Tools.clamp(height!, 0, maxHeight);
} else {
this._height = height;
}
@@ -541,7 +541,7 @@ export class Viewport {
// 2. changing curr skeleton
// 3. changing selection which cross viewport
// 4. changing the viewport size (also include change window size)
- // 5. changing the scroll bar position
+ // 5. changing the scroll bar position(click at certain pos of scrolltrack)
// Debug
// window.scene.getViewports()[0].scrollTo({x: 14.2, y: 1.8}, true)
scrollToBarPos(pos: Partial<IScrollBarPosition>) {
@@ -549,7 +549,7 @@ export class Viewport {
}
/**
- * scrolling by current position plus offset
+ * Srolling by current position plus delta.
* the most common case is triggered by scroll-timer(in sheet)
* @param delta
* @returns isLimited
@@ -560,23 +560,6 @@ export class Viewport {
return this._scrollToBarPosCore({ x, y }, isTrigger);
}
- scrollByBar(delta: Partial<IScrollBarPosition>, isTrigger = true) {
- this.scrollByBarDeltaValue(delta, isTrigger);
- const { x, y } = delta;
- this.onScrollByBar$.emitEvent({
- viewport: this,
- scrollX: this.scrollX,
- scrollY: this.scrollY,
- rawScrollX: x,
- rawScrollY: y,
- viewportScrollX: this.viewportScrollX,
- viewportScrollY: this.viewportScrollY,
- limitX: this._scrollBar?.limitX,
- limitY: this._scrollBar?.limitY,
- isTrigger,
- });
- }
-
/**
* Viewport scroll to certain position.
* @param pos
@@ -607,23 +590,6 @@ export class Viewport {
return this._scrollToViewportPosCore({ viewportScrollX, viewportScrollY }, isTrigger);
}
- /**
- * current position plus offset relatively
- * the caller no need to deal with the padding when frozen
- * @param offsetX
- * @param offsetY
- * @param isTrigger
- */
- scrollByOffset(offsetX = 0, offsetY = 0, isTrigger = true) {
- if (!this._scrollBar || this.isActive === false) {
- return;
- }
- const x = offsetX + this._paddingStartX;
- const y = offsetY + this._paddingStartY;
- const param = this.transViewportScroll2ScrollValue(x, y);
- return this.scrollByBarDeltaValue(param, isTrigger);
- }
-
transViewportScroll2ScrollValue(viewportScrollX: number, viewportScrollY: number) {
let x = viewportScrollX - this._paddingStartX;
let y = viewportScrollY - this._paddingStartY;
@@ -1135,7 +1101,7 @@ export class Viewport {
dispose() {
this.onMouseWheel$.complete();
this.onScrollAfter$.complete();
- this.onScrollBefore$.complete();
+ // this.onScrollBefore$.complete();
this.onScrollEnd$.complete();
this._scrollBar?.dispose();
this._cacheCanvas?.dispose();
@@ -1331,6 +1297,10 @@ export class Viewport {
// this._preScrollY = this.scrollY;
}
+ /**
+ * mock scrollend.
+ * @param scrollSubParam
+ */
private _emitScrollEnd$(scrollSubParam: IScrollObserverParam) {
clearTimeout(this._scrollStopNum);
this._scrollStopNum = setTimeout(() => {
@@ -1385,11 +1355,20 @@ export class Viewport {
isTrigger,
};
this._scrollBar?.makeDirty(true);
-
- this.onScrollBefore$.emitEvent(scrollSubParam);
this.onScrollAfter$.emitEvent(scrollSubParam);
this._emitScrollEnd$(scrollSubParam);
+ // exec sheet.command.scroll-view
+ this.onScrollByBar$.emitEvent({
+ viewport: this,
+ scrollX: this.scrollX,
+ scrollY: this.scrollY,
+ viewportScrollX: this.viewportScrollX,
+ viewportScrollY: this.viewportScrollY,
+ limitX: this._scrollBar?.limitX,
+ limitY: this._scrollBar?.limitY,
+ isTrigger,
+ });
return afterLimit;
}
@@ -1444,7 +1423,7 @@ export class Viewport {
this._scrollBar?.makeDirty(true);
- this.onScrollBefore$.emitEvent(scrollSubParam);
+ // set valid scrollInfo
this.onScrollAfter$.emitEvent(scrollSubParam);
this._emitScrollEnd$(scrollSubParam);
diff --git a/packages/sheets-ui/src/commands/commands/set-scroll.command.ts b/packages/sheets-ui/src/commands/commands/set-scroll.command.ts
index ce3a4e5dea..d7564b72db 100644
--- a/packages/sheets-ui/src/commands/commands/set-scroll.command.ts
+++ b/packages/sheets-ui/src/commands/commands/set-scroll.command.ts
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-import type { ICommand, IRange, Nullable } from '@univerjs/core';
import { CommandType, ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { IRenderManagerService } from '@univerjs/engine-render';
import { getSheetCommandTarget } from '@univerjs/sheets';
-import { IRenderManagerService } from '@univerjs/engine-render';
-import type { IScrollState } from '../../services/scroll-manager.service';
+import type { ICommand, IRange, Nullable } from '@univerjs/core';
+import { SheetsScrollRenderController } from '../../controllers/render-controllers/scroll.render-controller';
import { SheetScrollManagerService } from '../../services/scroll-manager.service';
import { SetScrollOperation } from '../operations/scroll.operation';
-import { SheetsScrollRenderController } from '../../controllers/render-controllers/scroll.render-controller';
+import type { IScrollState } from '../../services/scroll-manager.service';
export interface ISetScrollRelativeCommandParams {
offsetX?: number;
@@ -39,6 +39,7 @@ export interface IScrollCommandParams {
/**
* This command is used to manage the scroll by relative offset
* Usually triggered by wheel event.
+ * NOT same as ScrollCommand, which is usually triggered by scrollbar.
*/
export const SetScrollRelativeCommand: ICommand<ISetScrollRelativeCommandParams> = {
id: 'sheet.command.set-scroll-relative',
@@ -79,7 +80,8 @@ export const SetScrollRelativeCommand: ICommand<ISetScrollRelativeCommandParams>
/**
* This command is used to manage the scroll position of the current view by specifying the cell index of the top left cell
- * Usually triggered by click scrollbar or moving selection range.
+ * Usually triggered by dragging srcollbar and click scrolltrack or moving selection range.
+ * NOT same as SetScrollRelativeCommand which usually trigger by wheelevent.
*/
export const ScrollCommand: ICommand<IScrollCommandParams> = {
id: 'sheet.command.scroll-view',
diff --git a/packages/sheets-ui/src/commands/operations/scroll.operation.ts b/packages/sheets-ui/src/commands/operations/scroll.operation.ts
index d46d682888..a540a19967 100644
--- a/packages/sheets-ui/src/commands/operations/scroll.operation.ts
+++ b/packages/sheets-ui/src/commands/operations/scroll.operation.ts
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-import type { IOperation } from '@univerjs/core';
import { CommandType, IUniverInstanceService } from '@univerjs/core';
-
import { IRenderManagerService } from '@univerjs/engine-render';
-import type { IScrollStateWithSearchParam } from '../../services/scroll-manager.service';
+
+import type { IOperation } from '@univerjs/core';
import { SheetScrollManagerService } from '../../services/scroll-manager.service';
+import type { IScrollStateWithSearchParam } from '../../services/scroll-manager.service';
export const SetScrollOperation: IOperation<IScrollStateWithSearchParam> = {
id: 'sheet.operation.set-scroll',
@@ -31,7 +31,6 @@ export const SetScrollOperation: IOperation<IScrollStateWithSearchParam> = {
}
// freeze is handled by set-scroll.command.ts
-
const { unitId, sheetId, offsetX, offsetY, sheetViewStartColumn, sheetViewStartRow } = params;
const currentService = accessor.get(IUniverInstanceService);
const renderManagerService = accessor.get(IRenderManagerService);
diff --git a/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts
index d285782d24..432fc81012 100644
--- a/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/render-controllers/header-resize.render-controller.ts
@@ -15,8 +15,8 @@
*/
/* eslint-disable max-lines-per-function */
+/* eslint-disable complexity */
-import type { EventState, Nullable, Workbook } from '@univerjs/core';
import {
createInterceptorKey,
Disposable,
@@ -25,16 +25,17 @@ import {
InterceptorManager,
toDisposable,
} from '@univerjs/core';
-import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, SpreadsheetColumnHeader, SpreadsheetHeader } from '@univerjs/engine-render';
import { CURSOR_TYPE, Rect, SHEET_VIEWPORT_KEY, Vector2 } from '@univerjs/engine-render';
+import { DeltaColumnWidthCommand, DeltaRowHeightCommand, SetWorksheetRowIsAutoHeightCommand } from '@univerjs/sheets';
+import { Subscription } from 'rxjs';
+import type { EventState, Nullable, Workbook } from '@univerjs/core';
+import type { IMouseEvent, IPointerEvent, IRenderContext, IRenderModule, SpreadsheetColumnHeader, SpreadsheetHeader } from '@univerjs/engine-render';
+
import type {
IDeltaColumnWidthCommandParams,
IDeltaRowHeightCommand,
ISetWorksheetRowIsAutoHeightCommandParams,
} from '@univerjs/sheets';
-import { DeltaColumnWidthCommand, DeltaRowHeightCommand, SetWorksheetRowIsAutoHeightCommand } from '@univerjs/sheets';
-
-import { Subscription } from 'rxjs';
import { SHEET_COMPONENT_HEADER_LAYER_INDEX, SHEET_VIEW_KEY } from '../../common/keys';
import { SheetSkeletonManagerService } from '../../services/sheet-skeleton-manager.service';
import {
@@ -315,8 +316,8 @@ export class HeaderResizeRenderController extends Disposable implements IRenderM
const canvasMaxWidth = engine?.width || 0;
const viewPort = scene.getViewport(SHEET_VIEWPORT_KEY.VIEW_MAIN);
- const scrollBarHorizontalHeight = (viewPort?.getScrollBar()?.horizonBarRect?.height || 0) + 10;
- const scrollBarVerticalWidth = (viewPort?.getScrollBar()?.verticalBarRect?.width || 0) + 10;
+ const scrollBarHorizontalHeight = (viewPort?.getScrollBar()?.horizonScrollTrack?.height || 0) + 10;
+ const scrollBarVerticalWidth = (viewPort?.getScrollBar()?.verticalScrollTrack?.width || 0) + 10;
const transformCoord = getTransformCoord(evt.offsetX, evt.offsetY, scene, skeleton);
const { scaleX, scaleY } = scene.getAncestorScale();
diff --git a/packages/sheets-ui/src/controllers/render-controllers/scroll.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/scroll.render-controller.ts
index a66dd085ff..ed0ad37982 100644
--- a/packages/sheets-ui/src/controllers/render-controllers/scroll.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/render-controllers/scroll.render-controller.ts
@@ -14,28 +14,29 @@
* limitations under the License.
*/
-import type { IFreeze, IRange, IWorksheetData, Nullable, Workbook } from '@univerjs/core';
import {
Direction,
Disposable,
+ FOCUSING_SHEET,
ICommandService,
IContextService,
Inject,
Injector,
RANGE_TYPE, toDisposable } from '@univerjs/core';
-import type { IRenderContext, IRenderModule, IScrollObserverParam } from '@univerjs/engine-render';
-import { IRenderManagerService, SHEET_VIEWPORT_KEY } from '@univerjs/engine-render';
-import type { SheetsSelectionsService } from '@univerjs/sheets';
+import { IRenderManagerService, PointerInput, RENDER_CLASS_TYPE, SHEET_VIEWPORT_KEY } from '@univerjs/engine-render';
import { getSelectionsService, ScrollToCellOperation } from '@univerjs/sheets';
+import type { IFreeze, IRange, IWorksheetData, Nullable, Workbook } from '@univerjs/core';
+import type { IRenderContext, IRenderModule, IScrollObserverParam, IWheelEvent } from '@univerjs/engine-render';
+import type { SheetsSelectionsService } from '@univerjs/sheets';
-import { ScrollCommand } from '../../commands/commands/set-scroll.command';
-import type { IExpandSelectionCommandParams } from '../../commands/commands/set-selection.command';
+import { ScrollCommand, SetScrollRelativeCommand } from '../../commands/commands/set-scroll.command';
import { ExpandSelectionCommand, MoveSelectionCommand, MoveSelectionEnterAndTabCommand } from '../../commands/commands/set-selection.command';
-import type { IScrollState, IScrollStateSearchParam, IViewportScrollState } from '../../services/scroll-manager.service';
import { SheetScrollManagerService } from '../../services/scroll-manager.service';
-import type { ISheetSkeletonManagerParam } from '../../services/sheet-skeleton-manager.service';
import { SheetSkeletonManagerService } from '../../services/sheet-skeleton-manager.service';
import { getSheetObject } from '../utils/component-tools';
+import type { IExpandSelectionCommandParams } from '../../commands/commands/set-selection.command';
+import type { IScrollState, IScrollStateSearchParam, IViewportScrollState } from '../../services/scroll-manager.service';
+import type { ISheetSkeletonManagerParam } from '../../services/sheet-skeleton-manager.service';
const SHEET_NAVIGATION_COMMANDS = [MoveSelectionCommand.id, MoveSelectionEnterAndTabCommand.id];
@@ -55,7 +56,8 @@ export class SheetsScrollRenderController extends Disposable implements IRenderM
super();
this._initCommandListener();
- this._initScrollEventListener();
+ this._wheelEventListener();
+ this._scrollBarEventListener();
this._initSkeletonListener();
}
@@ -151,8 +153,84 @@ export class SheetsScrollRenderController extends Disposable implements IRenderM
return snapshot.freeze;
}
+ private _wheelEventListener() {
+ const { scene } = this._context;
+ if (!scene) return;
+
+ const viewMain = scene.getViewport(SHEET_VIEWPORT_KEY.VIEW_MAIN);
+ if (!viewMain) return;
+
+ this.disposeWithMe(
+ // eslint-disable-next-line complexity
+ scene.onMouseWheel$.subscribeEvent((evt: IWheelEvent, state) => {
+ if (evt.ctrlKey || !this._contextService.getContextValue(FOCUSING_SHEET)) {
+ return;
+ }
+
+ let offsetX = 0;
+ let offsetY = 0;
+
+ const isLimitedStore = viewMain.limitedScroll();
+ if (evt.inputIndex === PointerInput.MouseWheelX) {
+ const deltaFactor = Math.abs(evt.deltaX);
+ const scrollNum = deltaFactor;
+ // show more content on the right,evt.deltaX > 0, more content on the left, evt.deltaX < 0
+ offsetX = evt.deltaX > 0 ? scrollNum : -scrollNum;
+ this._commandService.executeCommand(SetScrollRelativeCommand.id, { offsetX });
+
+ if (scene.getParent().classType === RENDER_CLASS_TYPE.SCENE_VIEWER) {
+ if (!isLimitedStore?.isLimitedX) {
+ state.stopPropagation();
+ }
+ } else if (viewMain.isWheelPreventDefaultX) {
+ evt.preventDefault();
+ } else if (!isLimitedStore?.isLimitedX) {
+ evt.preventDefault();
+ }
+ }
+ if (evt.inputIndex === PointerInput.MouseWheelY) {
+ const deltaFactor = Math.abs(evt.deltaY);
+ let scrollNum = deltaFactor;
+ if (evt.shiftKey) {
+ scrollNum *= 3;
+ if (evt.deltaY > 0) {
+ offsetX = scrollNum;
+ } else {
+ offsetX = -scrollNum;
+ }
+ this._commandService.executeCommand(SetScrollRelativeCommand.id, { offsetX });
+
+ if (scene.getParent().classType === RENDER_CLASS_TYPE.SCENE_VIEWER) {
+ if (!isLimitedStore?.isLimitedX) {
+ state.stopPropagation();
+ }
+ } else if (viewMain.isWheelPreventDefaultX) {
+ evt.preventDefault();
+ } else if (!isLimitedStore?.isLimitedX) {
+ evt.preventDefault();
+ }
+ } else {
+ offsetY = evt.deltaY > 0 ? scrollNum : -scrollNum;
+ this._commandService.executeCommand(SetScrollRelativeCommand.id, { offsetY });
+
+ if (scene.getParent().classType === RENDER_CLASS_TYPE.SCENE_VIEWER) {
+ if (!isLimitedStore?.isLimitedY) {
+ state.stopPropagation();
+ }
+ } else if (viewMain.isWheelPreventDefaultY) {
+ evt.preventDefault();
+ } else if (!isLimitedStore?.isLimitedY) {
+ evt.preventDefault();
+ }
+ }
+ }
+ this._context.scene.makeDirty(true);
+ })
+ );
+ }
+
// eslint-disable-next-line max-lines-per-function
- private _initScrollEventListener() {
+ private _scrollBarEventListener() {
const { scene } = this._context;
if (scene == null) return;
@@ -238,6 +316,7 @@ export class SheetsScrollRenderController extends Disposable implements IRenderM
//#region scroll by bar
this.disposeWithMe(
+ // get scrollByBar event from viewport and exec ScrollCommand.id.
viewportMain.onScrollByBar$.subscribeEvent((param) => {
const skeleton = this._sheetSkeletonManagerService.getCurrent()?.skeleton;
if (skeleton == null || param.isTrigger === false) {
@@ -257,6 +336,7 @@ export class SheetsScrollRenderController extends Disposable implements IRenderM
viewportScrollY
);
+ // NOT same as SetScrollRelativeCommand. that was exec in sheetRenderController
this._commandService.executeCommand(ScrollCommand.id, {
sheetViewStartRow: row + (freeze?.ySplit || 0),
sheetViewStartColumn: column + (freeze?.xSplit || 0),
diff --git a/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts
index 90f5f72096..922465b977 100644
--- a/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/render-controllers/sheet.render-controller.ts
@@ -14,11 +14,9 @@
* limitations under the License.
*/
-import { CommandType, FOCUSING_SHEET, ICommandService, IContextService, Inject, Optional, Rectangle, RxDisposable } from '@univerjs/core';
+import { CommandType, ICommandService, IContextService, Inject, Optional, Rectangle, RxDisposable } from '@univerjs/core';
import {
- PointerInput,
Rect,
- RENDER_CLASS_TYPE,
ScrollBar,
SHEET_EXTENSION_PREFIX,
SHEET_VIEWPORT_KEY,
@@ -31,8 +29,7 @@ import { COMMAND_LISTENER_SKELETON_CHANGE, COMMAND_LISTENER_VALUE_CHANGE, MoveRa
import { ITelemetryService } from '@univerjs/telemetry';
import { Subject, withLatestFrom } from 'rxjs';
import type { ICommandInfo, IExecutionOptions, IRange, Nullable, Workbook, Worksheet } from '@univerjs/core';
-import type { IAfterRender$Info, IBasicFrameInfo, IExtendFrameInfo, IRenderContext, IRenderModule, ISummaryFrameInfo, ITimeMetric, IViewportInfos, IWheelEvent, Scene } from '@univerjs/engine-render';
-import { SetScrollRelativeCommand } from '../../commands/commands/set-scroll.command';
+import type { IAfterRender$Info, IBasicFrameInfo, IExtendFrameInfo, IRenderContext, IRenderModule, ISummaryFrameInfo, ITimeMetric, IViewportInfos, Scene } from '@univerjs/engine-render';
import {
SHEET_COMPONENT_HEADER_LAYER_INDEX,
@@ -364,7 +361,7 @@ export class SheetRenderController extends RxDisposable implements IRenderModule
const { rowHeader, columnHeader } = worksheet.getConfig();
const { viewMain } = this._initViewports(scene, rowHeader, columnHeader);
- this._initMouseWheel(scene, viewMain);
+ // this._initMouseWheel(scene, viewMain);
const _scrollBar = new ScrollBar(viewMain);
scene.attachControl();
@@ -547,86 +544,4 @@ export class SheetRenderController extends RxDisposable implements IRenderModule
private _spreadsheetViewports(scene: Scene) {
return scene.getViewports().filter((v) => ['viewMain', 'viewMainLeftTop', 'viewMainTop', 'viewMainLeft'].includes(v.viewportKey));
}
-
- // mouse scroll
- private _initMouseWheel(scene: Scene, viewMain: Viewport) {
- this.disposeWithMe(
- // eslint-disable-next-line complexity
- scene.onMouseWheel$.subscribeEvent((evt: IWheelEvent, state) => {
- if (evt.ctrlKey || !this._contextService.getContextValue(FOCUSING_SHEET)) {
- return;
- }
-
- let offsetX = 0;
- let offsetY = 0;
-
- const isLimitedStore = viewMain.limitedScroll();
- if (evt.inputIndex === PointerInput.MouseWheelX) {
- const deltaFactor = Math.abs(evt.deltaX);
- // let magicNumber = deltaFactor < 40 ? 2 : deltaFactor < 80 ? 3 : 4;
- const scrollNum = deltaFactor;
- // show more content on the right,evt.deltaX > 0
- // show more content on the left, evt.deltaX < 0
- if (evt.deltaX > 0) {
- offsetX = scrollNum;
- } else {
- offsetX = -scrollNum;
- }
- this._commandService.executeCommand(SetScrollRelativeCommand.id, { offsetX });
-
- if (scene.getParent().classType === RENDER_CLASS_TYPE.SCENE_VIEWER) {
- if (!isLimitedStore?.isLimitedX) {
- state.stopPropagation();
- }
- } else if (viewMain.isWheelPreventDefaultX) {
- evt.preventDefault();
- } else if (!isLimitedStore?.isLimitedX) {
- evt.preventDefault();
- }
- }
- if (evt.inputIndex === PointerInput.MouseWheelY) {
- const deltaFactor = Math.abs(evt.deltaY);
- let scrollNum = deltaFactor;
- if (evt.shiftKey) {
- scrollNum *= 3;
- if (evt.deltaY > 0) {
- offsetX = scrollNum;
- } else {
- offsetX = -scrollNum;
- }
- this._commandService.executeCommand(SetScrollRelativeCommand.id, { offsetX });
-
- if (scene.getParent().classType === RENDER_CLASS_TYPE.SCENE_VIEWER) {
- if (!isLimitedStore?.isLimitedX) {
- state.stopPropagation();
- }
- } else if (viewMain.isWheelPreventDefaultX) {
- evt.preventDefault();
- } else if (!isLimitedStore?.isLimitedX) {
- evt.preventDefault();
- }
- } else {
- if (evt.deltaY > 0) {
- offsetY = scrollNum;
- } else {
- offsetY = -scrollNum;
- }
- this._commandService.executeCommand(SetScrollRelativeCommand.id, { offsetY });
-
- if (scene.getParent().classType === RENDER_CLASS_TYPE.SCENE_VIEWER) {
- if (!isLimitedStore?.isLimitedY) {
- state.stopPropagation();
- }
- } else if (viewMain.isWheelPreventDefaultY) {
- evt.preventDefault();
- } else if (!isLimitedStore?.isLimitedY) {
- evt.preventDefault();
- }
- }
- }
-
- this._context.scene.makeDirty(true);
- })
- );
- }
}
diff --git a/packages/sheets-ui/src/services/scroll-manager.service.ts b/packages/sheets-ui/src/services/scroll-manager.service.ts
index d92694be80..eaa90a0f2d 100644
--- a/packages/sheets-ui/src/services/scroll-manager.service.ts
+++ b/packages/sheets-ui/src/services/scroll-manager.service.ts
@@ -67,13 +67,13 @@ export class SheetScrollManagerService implements IRenderModule {
*/
private readonly _scrollStateMap: IScrollStateMap = new Map();
/**
- * a subject for current sheet scrollInfo
+ * a subject for current sheet scrollInfo, no limit by viewport.
*/
- private readonly _scrollInfo$ = new BehaviorSubject<Nullable<IScrollState>>(null);
+ private readonly _rawscrollInfo$ = new BehaviorSubject<Nullable<IScrollState>>(null);
/**
* a subject for current sheet scrollInfo ( events, ex wheel event and point events add deltaXY to rawScrollInfo$)
*/
- readonly rawScrollInfo$ = this._scrollInfo$.asObservable();
+ readonly rawScrollInfo$ = this._rawscrollInfo$.asObservable();
/**
* a subject for current valid scrollInfo, viewport@_scrollCore would limit rawScrollInfo$ exclude negative value or over max value.
* use this subject not rawScrollInfo$ when get scrolling state of viewport.
@@ -96,7 +96,7 @@ export class SheetScrollManagerService implements IRenderModule {
}
dispose(): void {
- this._scrollInfo$.complete();
+ this._rawscrollInfo$.complete();
}
setSearchParam(param: IScrollStateSearchParam) {
@@ -117,7 +117,7 @@ export class SheetScrollManagerService implements IRenderModule {
}
/**
- * set scrollInfo by SetScrollOperation, call by scroll operation
+ * Set scrollInfo by SetScrollOperation, call by ScrollCommand.id.
* @param param
*/
setScrollInfoAndEmitEvent(param: IScrollStateWithSearchParam) {
@@ -228,6 +228,6 @@ export class SheetScrollManagerService implements IRenderModule {
const scrollInfo = this._getCurrentScroll(param);
// subscriber can be found in scrollManagerService.rawScrollInfo$.subscribe
- this._scrollInfo$.next(scrollInfo);
+ this._rawscrollInfo$.next(scrollInfo);
}
}