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: mouse enter leave (#4696)

lumix2bfba12b4109
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png
index 3535b29994..0d71f2abd4 100644
Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png differ
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png
index 6d21db0aee..ef0450f85d 100644
Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png differ
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png
index a9b2e95d41..849483a5c0 100644
Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png differ
diff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png
index 47a3b723c3..8a8e2d941f 100644
Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png differ
diff --git a/packages/engine-render/src/scene.input-manager.ts b/packages/engine-render/src/scene.input-manager.ts
index d4ec6d361d..5099eec446 100644
--- a/packages/engine-render/src/scene.input-manager.ts
+++ b/packages/engine-render/src/scene.input-manager.ts
@@ -14,13 +14,14 @@
* limitations under the License.
*/
-import type { PointerEvent } from 'react';
+import type { Nullable } from '@univerjs/core';
+import type { PointerEvent } from 'react';
import type { Subscription } from 'rxjs';
import type { BaseObject } from './base-object';
import type { IDragEvent, IEvent, IKeyboardEvent, IMouseEvent, IPointerEvent, IWheelEvent } from './basics/i-events';
import type { ISceneInputControlOptions, Scene } from './scene';
-import { Disposable, type Nullable, toDisposable } from '@univerjs/core';
+import { Disposable, toDisposable } from '@univerjs/core';
import { RENDER_CLASS_TYPE } from './basics/const';
import { DeviceType, PointerInput } from './basics/i-events';
import { Vector2 } from './basics/vector2';
@@ -90,7 +91,7 @@ export class InputManager extends Disposable {
// Handle events such as triggering mouseleave and mouseenter.
mouseLeaveEnterHandler(evt: IMouseEvent) {
- const o = this._currentObject;
+ const o = this._currentObject || this.capturedObject;
if (o === null || o === undefined) {
this._currentMouseEnterPicked?.triggerPointerLeave(evt);
this._currentMouseEnterPicked = null;
@@ -143,11 +144,11 @@ export class InputManager extends Disposable {
}
const currentObject = this._currentObject = this._getObjectAtPos(evt.offsetX, evt.offsetY);
- const isStop = currentObject?.triggerPointerMove(evt);
+ const isStop = (currentObject || this.capturedObject)?.triggerPointerMove(evt);
this.mouseLeaveEnterHandler(evt);
- if (this._checkDirectSceneEventTrigger(!isStop, this._currentObject)) {
+ if (!isStop && this._shouldDispatchEventToScene(currentObject)) {
this._scene.onPointerMove$.emitEvent(evt);
this._scene.getEngine()?.setCapture();
}
@@ -162,7 +163,7 @@ export class InputManager extends Disposable {
const currentObject = this._getObjectAtPos(evt.offsetX, evt.offsetY);
const isStop = currentObject?.triggerPointerDown(evt);
- if (this._checkDirectSceneEventTrigger(!isStop, currentObject)) {
+ if (!isStop && this._shouldDispatchEventToScene(currentObject)) {
this._scene.onPointerDown$.emitEvent(evt);
}
}
@@ -176,7 +177,7 @@ export class InputManager extends Disposable {
const currentObject = this._getObjectAtPos(evt.offsetX, evt.offsetY);
const isStop = currentObject?.triggerPointerUp(evt);
- if (this._checkDirectSceneEventTrigger(!isStop, currentObject)) {
+ if (!isStop && this._shouldDispatchEventToScene(currentObject)) {
this._scene.onPointerUp$.emitEvent(evt);
}
@@ -203,8 +204,7 @@ export class InputManager extends Disposable {
const viewportMain = this._scene.getMainViewport();
viewportMain.onMouseWheel$.emitEvent(evt);
- // what is checkDirectSceneEventTrigger?? for what ???
- if (this._checkDirectSceneEventTrigger(!isStop, currentObject)) {
+ if (!isStop && this._shouldDispatchEventToScene(currentObject)) {
this._scene.onMouseWheel$.emitEvent(evt);
}
}
@@ -238,7 +238,7 @@ export class InputManager extends Disposable {
this.dragLeaveEnterHandler(evt);
- if (this._checkDirectSceneEventTrigger(!isStop, this._currentObject)) {
+ if (!isStop && this._shouldDispatchEventToScene(this._currentObject)) {
this._scene.onDragOver$.emitEvent(evt);
this._scene.getEngine()?.setCapture();
}
@@ -248,7 +248,7 @@ export class InputManager extends Disposable {
const currentObject = this._getObjectAtPos(evt.offsetX, evt.offsetY);
const isStop = currentObject?.triggerDrop(evt);
- if (this._checkDirectSceneEventTrigger(!isStop, currentObject)) {
+ if (!isStop && this._shouldDispatchEventToScene(currentObject)) {
this._scene.onDrop$.emitEvent(evt);
}
}
@@ -372,7 +372,7 @@ export class InputManager extends Disposable {
}
/**
- * Just call this._scene.pick, nothing special.
+ * Get the object under the pointer, if scene.event is disabled, return null.
* @param offsetX
* @param offsetY
*/
@@ -380,21 +380,58 @@ export class InputManager extends Disposable {
return this._scene?.pick(Vector2.FromArray([offsetX, offsetY]));
}
- private _checkDirectSceneEventTrigger(isTrigger: boolean, currentObject: Nullable<Scene | BaseObject>) {
- let notObject = false;
+ /**
+ *
+ * If currentObject is null, return true
+ * @param isTrigger
+ * @param currentObject
+ * @returns
+ */
+
+ // The return value of this method is so weird! return type is object and boolean???
+ // TODO @lumixraku
+ // private _shouldDispatchEventToScene(isTrigger: boolean, currentObject: Nullable<Scene | BaseObject>) {
+ // let notObject = false;
+ // if (currentObject == null) {
+ // notObject = true;
+ // }
+
+ // let isNotInSceneViewer = true;
+ // if (currentObject && currentObject.classType === RENDER_CLASS_TYPE.BASE_OBJECT) {
+ // const scene = (currentObject as BaseObject).getScene() as Scene;
+ // if (scene) {
+ // const parent = scene.getParent();
+ // isNotInSceneViewer = parent.classType !== RENDER_CLASS_TYPE.SCENE_VIEWER;
+ // }
+ // }
+ // return (!this._scene.objectsEvented && isTrigger && isNotInSceneViewer) || notObject;
+
+ // }
+
+ private _shouldDispatchEventToScene(currentObject: Nullable<Scene | BaseObject>): boolean {
+ // 1. Check for empty object
if (currentObject == null) {
- notObject = true;
+ return true;
}
- let isNotInSceneViewer = true;
- if (currentObject && currentObject.classType === RENDER_CLASS_TYPE.BASE_OBJECT) {
- const scene = (currentObject as BaseObject).getScene() as Scene;
+ // 2. If the scene allows object events, no need to dispatch to the scene
+ if (this._scene.objectsEvented) {
+ return false;
+ }
+
+ // 3. Check if it is in the SceneViewer
+ return !this._isObjectInSceneViewer(currentObject);
+ }
+
+ private _isObjectInSceneViewer(obj: Scene | BaseObject): boolean {
+ if (obj && obj.classType === RENDER_CLASS_TYPE.BASE_OBJECT) {
+ const scene = (obj as BaseObject).getScene() as Scene;
if (scene) {
const parent = scene.getParent();
- isNotInSceneViewer = parent.classType !== RENDER_CLASS_TYPE.SCENE_VIEWER;
+ return parent.classType === RENDER_CLASS_TYPE.SCENE_VIEWER;
}
}
- return (!this._scene.objectsEvented && isTrigger && isNotInSceneViewer) || notObject;
+ return false;
}
/**
@@ -451,4 +488,8 @@ export class InputManager extends Disposable {
this._doubleClickOccurred = 0;
clearTimeout(this._delayedTimeout);
}
+
+ get capturedObject() {
+ return this._scene._capturedObject;
+ }
}
diff --git a/packages/engine-render/src/scene.ts b/packages/engine-render/src/scene.ts
index fc7edec6d2..df0c8d67ce 100644
--- a/packages/engine-render/src/scene.ts
+++ b/packages/engine-render/src/scene.ts
@@ -964,7 +964,7 @@ export class Scene extends Disposable {
}
/**
- * Get the object under the pointer, if scene.event is disabled, the object is null.
+ * Get the object under the pointer, if scene.event is disabled, return null.
* @param {Vector2} coord
* @return {Nullable<BaseObject | Scene>} object under the pointer
*/
@@ -1239,11 +1239,27 @@ export class Scene extends Disposable {
* Then only scene itself can response to pointer event, all objects under the scene would not.
* see sceneInputManager@_onPointerMove
*/
+ // 禁用对象事件
disableObjectsEvent() {
+ // 将_evented属性设置为false
this._evented = false;
}
enableObjectsEvent() {
this._evented = true;
}
+
+ _capturedObject: BaseObject | null = null;
+
+ get capturedObject() {
+ return this._capturedObject;
+ }
+
+ setCaptureObject(o: BaseObject) {
+ this._capturedObject = o;
+ }
+
+ releaseCapturedObject() {
+ this._capturedObject = null;
+ }
}
diff --git a/packages/engine-render/src/shape/base-scroll-bar.ts b/packages/engine-render/src/shape/base-scroll-bar.ts
index 0079da0c56..a1cdc318f9 100644
--- a/packages/engine-render/src/shape/base-scroll-bar.ts
+++ b/packages/engine-render/src/shape/base-scroll-bar.ts
@@ -14,12 +14,13 @@
* limitations under the License.
*/
-import type { Vector2 } from '../basics/vector2';
+import type { Nullable } from '@univerjs/core';
+import type { Vector2 } from '../basics/vector2';
import type { UniverRenderingContext } from '../context';
import type { Scene } from '../scene';
import type { Rect } from './rect';
-import { Disposable, type Nullable } from '@univerjs/core';
+import { Disposable } from '@univerjs/core';
export interface IScrollBarProps {
thumbMargin?: number;
@@ -49,24 +50,18 @@ export abstract class BaseScrollBar extends Disposable {
enableVertical: boolean = true;
- horizontalThumbWidth: number = 0;
-
+ horizontalThumbSize: number = 0;
horizontalMinusMiniThumb: number = 0;
-
horizontalBarWidth: number = 0;
- verticalThumbHeight: number = 0;
+ horizonScrollTrack: Nullable<Rect>;
+ horizonThumbRect: Nullable<Rect>;
+ verticalThumbSize: number = 0;
verticalBarHeight: number = 0;
-
verticalMinusMiniThumb: number = 0;
- horizonScrollTrack: Nullable<Rect>;
-
- horizonThumbRect: Nullable<Rect>;
-
verticalScrollTrack: Nullable<Rect>;
-
verticalThumbRect: Nullable<Rect>;
placeholderBarRect: Nullable<Rect>;
@@ -75,27 +70,27 @@ export abstract class BaseScrollBar extends Disposable {
if (!this.horizonThumbRect?.visible) {
return 0;
}
- return this.horizontalBarWidth - this.horizontalThumbWidth;
+ return this.horizontalBarWidth - this.horizontalThumbSize;
}
get limitY() {
if (!this.verticalThumbRect?.visible) {
return 0;
}
- return this.verticalBarHeight - this.verticalThumbHeight;
+ return this.verticalBarHeight - this.verticalThumbSize;
}
get ratioScrollX(): number {
if (
this.enableHorizontal === false ||
- this.horizontalThumbWidth === undefined ||
+ this.horizontalThumbSize === undefined ||
this.horizontalBarWidth === undefined
) {
return 1;
}
const ratio = (
- ((this.horizontalThumbWidth - this.horizontalMinusMiniThumb) * this.miniThumbRatioX) /
+ ((this.horizontalThumbSize - this.horizontalMinusMiniThumb) * this.miniThumbRatioX) /
this.horizontalBarWidth
);
@@ -109,13 +104,13 @@ export abstract class BaseScrollBar extends Disposable {
get ratioScrollY(): number {
if (
this.enableVertical === false ||
- this.verticalThumbHeight === undefined ||
+ this.verticalThumbSize === undefined ||
this.verticalBarHeight === undefined
) {
return 1;
}
const ratio = (
- ((this.verticalThumbHeight - this.verticalMinusMiniThumb) * this.miniThumbRatioY) / this.verticalBarHeight
+ ((this.verticalThumbSize - this.verticalMinusMiniThumb) * this.miniThumbRatioY) / this.verticalBarHeight
);
if (Number.isNaN(ratio)) {
@@ -126,13 +121,13 @@ export abstract class BaseScrollBar extends Disposable {
}
get miniThumbRatioX() {
- const limit = this.horizontalBarWidth - this.horizontalThumbWidth;
+ const limit = this.horizontalBarWidth - this.horizontalThumbSize;
if (limit === 0) {
return 0;
}
- const actual = this.horizontalBarWidth - (this.horizontalThumbWidth - this.horizontalMinusMiniThumb);
+ const actual = this.horizontalBarWidth - (this.horizontalThumbSize - this.horizontalMinusMiniThumb);
if (actual === 0) {
return 0;
@@ -142,13 +137,13 @@ export abstract class BaseScrollBar extends Disposable {
}
get miniThumbRatioY() {
- const limit = this.verticalBarHeight - this.verticalThumbHeight;
+ const limit = this.verticalBarHeight - this.verticalThumbSize;
if (limit === 0) {
return 0;
}
- const actual = this.verticalBarHeight - (this.verticalThumbHeight - this.verticalMinusMiniThumb);
+ const actual = this.verticalBarHeight - (this.verticalThumbSize - this.verticalMinusMiniThumb);
if (actual === 0) {
return 0;
diff --git a/packages/engine-render/src/shape/scroll-bar.ts b/packages/engine-render/src/shape/scroll-bar.ts
index 464e7a65e3..dfe5dc1b4b 100644
--- a/packages/engine-render/src/shape/scroll-bar.ts
+++ b/packages/engine-render/src/shape/scroll-bar.ts
@@ -51,12 +51,17 @@ export class ScrollBar extends BaseScrollBar {
private _verticalPointerUpSub: Nullable<Subscription>;
/**
- * The thickness of a scrolling bar.
+ * The thickness of a scrolling track
+ * ThumbSize = barSize - thumbMargin * 2
*/
barSize = 14;
barBorder = 1;
+ /**
+ * The margin between thumb and bar.
+ * ThumbSize = barSize - thumbMargin * 2
+ */
thumbMargin = 2;
thumbLengthRatio = 1;
@@ -64,14 +69,10 @@ export class ScrollBar extends BaseScrollBar {
/**
* todo: @DR-univer。 Mainly inject themeService in order to obtain colors.
*/
- thumbBackgroundColor = '#cccccc';
-
- thumbHoverBackgroundColor = '#b2b2b2';
-
- thumbActiveBackgroundColor = '#999999';
-
+ thumbBackgroundColor = 'rgba(24, 28, 42, 0.20)';
+ thumbHoverBackgroundColor = 'rgba(24, 28, 42, 0.30)';
+ thumbActiveBackgroundColor = 'rgba(24, 28, 42, 0.40)';
barBackgroundColor = 'rgba(255,255,255,0.5)';
-
barBorderColor = 'rgba(255,255,255,0.7)';
/**
@@ -85,6 +86,10 @@ export class ScrollBar extends BaseScrollBar {
private _eventSub = new Subscription();
+ get scrollHandleThickness() {
+ return Math.max(0, this.barSize - this.thumbMargin * 2);
+ }
+
constructor(view: Viewport, props?: IScrollBarProps) {
super();
if (!view) {
@@ -220,14 +225,15 @@ export class ScrollBar extends BaseScrollBar {
this.horizontalMinusMiniThumb = 0;
this.horizontalBarWidth = parentWidth - (this.enableVertical ? this.barSize : 0) - this.barBorder;
- this.horizontalThumbWidth =
+
+ this.horizontalThumbSize =
((this.horizontalBarWidth * (this.horizontalBarWidth - this.barBorder)) / contentWidth) *
this.thumbLengthRatio;
// this._horizontalThumbWidth = this._horizontalThumbWidth < MINI_THUMB_SIZE ? MINI_THUMB_SIZE : this._horizontalThumbWidth;
- if (this.horizontalThumbWidth < this.minThumbSizeH) {
- this.horizontalMinusMiniThumb = this.minThumbSizeH - this.horizontalThumbWidth;
- this.horizontalThumbWidth = this.minThumbSizeH;
+ if (this.horizontalThumbSize < this.minThumbSizeH) {
+ this.horizontalMinusMiniThumb = this.minThumbSizeH - this.horizontalThumbSize;
+ this.horizontalThumbSize = this.minThumbSizeH;
}
this.horizonScrollTrack?.transformByState({
@@ -237,11 +243,11 @@ export class ScrollBar extends BaseScrollBar {
height: Math.max(0, this.barSize - this.barBorder),
});
- if (this.horizontalThumbWidth >= parentWidth - this.barSize) {
+ if (this.horizontalThumbSize >= parentWidth - this.barSize) {
// why hide the thumb rect ?
- this.horizonThumbRect?.setProps({
- visible: false,
- });
+ // this.horizonThumbRect?.setProps({
+ // visible: false,
+ // });
} else {
if (!this.horizonThumbRect?.visible) {
this.horizonThumbRect?.setProps({
@@ -252,8 +258,8 @@ export class ScrollBar extends BaseScrollBar {
this.horizonThumbRect?.transformByState({
left: this._viewport.scrollX,
top: parentHeight - this.barSize + this.thumbMargin,
- width: this.horizontalThumbWidth,
- height: Math.max(0, this.barSize - this.thumbMargin * 2),
+ width: this.horizontalThumbSize,
+ height: this.scrollHandleThickness,
});
}
}
@@ -265,12 +271,12 @@ export class ScrollBar extends BaseScrollBar {
this.verticalMinusMiniThumb = 0;
this.verticalBarHeight = parentHeight - (this.enableHorizontal ? this.barSize : 0) - this.barBorder;
- this.verticalThumbHeight =
+ this.verticalThumbSize =
((this.verticalBarHeight * this.verticalBarHeight) / contentHeight) * this.thumbLengthRatio;
// this._verticalThumbHeight = this._verticalThumbHeight < MINI_THUMB_SIZE ? MINI_THUMB_SIZE : this._verticalThumbHeight;
- if (this.verticalThumbHeight < this.minThumbSizeV) {
- this.verticalMinusMiniThumb = this.minThumbSizeV - this.verticalThumbHeight;
- this.verticalThumbHeight = this.minThumbSizeV;
+ if (this.verticalThumbSize < this.minThumbSizeV) {
+ this.verticalMinusMiniThumb = this.minThumbSizeV - this.verticalThumbSize;
+ this.verticalThumbSize = this.minThumbSizeV;
}
this.verticalScrollTrack?.transformByState({
@@ -280,11 +286,11 @@ export class ScrollBar extends BaseScrollBar {
height: this.verticalBarHeight,
});
- if (this.verticalThumbHeight >= parentHeight - this.barSize) {
+ if (this.verticalThumbSize >= parentHeight - this.barSize) {
// why hide the thumb rect ?
- this.verticalThumbRect?.setProps({
- visible: false,
- });
+ // this.verticalThumbRect?.setProps({
+ // visible: false,
+ // });
} else {
if (!this.verticalThumbRect?.visible) {
this.verticalThumbRect?.setProps({
@@ -295,8 +301,8 @@ export class ScrollBar extends BaseScrollBar {
this.verticalThumbRect?.transformByState({
left: parentWidth - this.barSize + this.thumbMargin,
top: this._viewport.scrollY,
- width: Math.max(0, this.barSize - this.thumbMargin * 2),
- height: this.verticalThumbHeight,
+ width: this.scrollHandleThickness,
+ height: this.verticalThumbSize,
});
}
}
@@ -345,13 +351,13 @@ export class ScrollBar extends BaseScrollBar {
const mainScene = this._mainScene || this._viewport.scene;
if (this.verticalThumbRect) {
- this._eventSub.add(this.verticalThumbRect.onPointerEnter$.subscribeEvent((_evt: unknown, _state: EventState) => {
- this._hoverFunc(this.thumbHoverBackgroundColor!, this.verticalThumbRect!);
+ this._eventSub.add(this.verticalThumbRect.onPointerEnter$.subscribeEvent((evt: unknown, state: EventState) => {
+ this._hoverFunc(this.thumbHoverBackgroundColor!, this.verticalThumbRect!)(evt, state);
}));
}
if (this.verticalThumbRect) {
- this._eventSub.add(this.verticalThumbRect.onPointerLeave$.subscribeEvent((_evt: unknown, _state: EventState) => {
- this._hoverFunc(this.thumbHoverBackgroundColor!, this.verticalThumbRect!);
+ this._eventSub.add(this.verticalThumbRect.onPointerLeave$.subscribeEvent((evt: unknown, state: EventState) => {
+ this._hoverFunc(this.thumbBackgroundColor!, this.verticalThumbRect!)(evt, state);
}));
}
@@ -360,7 +366,7 @@ export class ScrollBar extends BaseScrollBar {
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,
+ y: e.offsetY - this._viewport.top - this.verticalThumbSize / 2,
});
state.stopPropagation();
@@ -380,6 +386,7 @@ export class ScrollBar extends BaseScrollBar {
srcElement?.setProps({
fill: this.thumbActiveBackgroundColor!,
});
+ mainScene.setCaptureObject(this.verticalThumbRect!);
mainScene.disableObjectsEvent();
this.makeViewDirty(true);
state.stopPropagation();
@@ -401,25 +408,19 @@ export class ScrollBar extends BaseScrollBar {
});
this._verticalPointerUpSub = mainScene.onPointerUp$.subscribeEvent((_evt: unknown, _state: EventState) => {
- // const e = evt as IPointerEvent | IMouseEvent;
const srcElement = this.verticalThumbRect;
this._isVerticalMove = false;
- // srcElement.fill = this._thumbBackgroundColor!;
+ mainScene.releaseCapturedObject();
mainScene.enableObjectsEvent();
srcElement?.setProps({
- fill: this.thumbBackgroundColor!,
+ fill: this.thumbHoverBackgroundColor!,
});
- // srcElement.makeDirty(true);
this.makeViewDirty(true);
});
}
- private _hoverFunc(color: string, object: Rect) {
- return (evt: unknown, state: EventState) => {
- if (this._isHorizonMove || this._isVerticalMove) {
- return;
- }
- const e = evt as IPointerEvent | IMouseEvent;
+ private _hoverFunc(color: string, object: Rect): (evt: unknown, state: EventState) => void {
+ return (_evt: unknown, _state: EventState) => {
const srcElement = object;
srcElement.setProps({
fill: color,
@@ -435,22 +436,14 @@ export class ScrollBar extends BaseScrollBar {
const mainScene = this._mainScene || this._viewport.scene;
- // this.horizonThumbRect?.on(
- // EVENT_TYPE.PointerEnter,
- // this._hoverFunc(this.thumbHoverBackgroundColor!, this.horizonThumbRect)
- // );
- // this.horizonThumbRect?.on(
- // EVENT_TYPE.PointerLeave,
- // this._hoverFunc(this.thumbBackgroundColor!, this.horizonThumbRect)
- // );
if (this.horizonThumbRect) {
- this._eventSub.add(this.horizonThumbRect.onPointerEnter$.subscribeEvent((_evt: unknown, _state: EventState) => {
- this._hoverFunc(this.thumbHoverBackgroundColor!, this.horizonThumbRect!);
+ this._eventSub.add(this.horizonThumbRect.onPointerEnter$.subscribeEvent((evt: unknown, state: EventState) => {
+ this._hoverFunc(this.thumbHoverBackgroundColor, this.horizonThumbRect!)(evt, state);
}));
}
if (this.horizonThumbRect) {
- this._eventSub.add(this.horizonThumbRect.onPointerLeave$.subscribeEvent((_evt: unknown, _state: EventState) => {
- this._hoverFunc(this.thumbHoverBackgroundColor!, this.horizonThumbRect!);
+ this._eventSub.add(this.horizonThumbRect.onPointerLeave$.subscribeEvent((evt: unknown, state: EventState) => {
+ this._hoverFunc(this.thumbBackgroundColor, this.horizonThumbRect!)(evt, state);
}));
}
@@ -459,7 +452,7 @@ export class ScrollBar extends BaseScrollBar {
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,
+ x: e.offsetX - this._viewport.left - this.horizontalThumbSize / 2,
});
state.stopPropagation();
}));
@@ -472,11 +465,11 @@ export class ScrollBar extends BaseScrollBar {
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.setCaptureObject(this.horizonThumbRect!);
mainScene.disableObjectsEvent();
state.stopPropagation();
}));
@@ -497,12 +490,11 @@ export class ScrollBar extends BaseScrollBar {
this._horizonPointerUpSub = mainScene.onPointerUp$.subscribeEvent((evt: unknown, state: EventState) => {
const srcElement = this.horizonThumbRect;
this._isHorizonMove = false;
+ mainScene.releaseCapturedObject();
mainScene.enableObjectsEvent();
- // srcElement.fill = this._thumbBackgroundColor!;
srcElement?.setProps({
- fill: this.thumbBackgroundColor!,
+ fill: this.thumbHoverBackgroundColor!,
});
- // srcElement.makeDirty(true);
this.makeViewDirty(true);
});
}
diff --git a/packages/sheets-ui/src/services/selection/base-selection-render.service.ts b/packages/sheets-ui/src/services/selection/base-selection-render.service.ts
index 03ca95b7aa..ad07dd91b6 100644
--- a/packages/sheets-ui/src/services/selection/base-selection-render.service.ts
+++ b/packages/sheets-ui/src/services/selection/base-selection-render.service.ts
@@ -25,16 +25,19 @@ import type {
IRange,
IRangeWithCoord,
IStyleSheet,
- Nullable } from '@univerjs/core';
+ Nullable,
+} from '@univerjs/core';
import type { IMouseEvent, IPointerEvent, IRenderModule, Scene, SpreadsheetSkeleton, Viewport } from '@univerjs/engine-render';
+import type { ISelectionStyle, ISelectionWithCoord, ISelectionWithStyle } from '@univerjs/sheets';
import type { IShortcutService } from '@univerjs/ui';
import type { Observable, Subscription } from 'rxjs';
import type { SheetSkeletonManagerService } from '../sheet-skeleton-manager.service';
import {
- convertCellToRange, createIdentifier, Disposable, InterceptorManager, RANGE_TYPE, ThemeService } from '@univerjs/core';
-import { ScrollTimer, ScrollTimerType, SHEET_VIEWPORT_KEY, Vector2 } from '@univerjs/engine-render';
+ convertCellToRange, createIdentifier, Disposable, InterceptorManager, RANGE_TYPE, ThemeService,
+} from '@univerjs/core';
-import { type ISelectionStyle, type ISelectionWithCoord, type ISelectionWithStyle, REF_SELECTIONS_ENABLED, SELECTIONS_ENABLED } from '@univerjs/sheets';
+import { ScrollTimer, ScrollTimerType, SHEET_VIEWPORT_KEY, Vector2 } from '@univerjs/engine-render';
+import { REF_SELECTIONS_ENABLED, SELECTIONS_ENABLED } from '@univerjs/sheets';
import { BehaviorSubject, Subject } from 'rxjs';
import { SHEET_COMPONENT_SELECTION_LAYER_INDEX } from '../../common/keys';
import { genNormalSelectionStyle, RANGE_FILL_PERMISSION_CHECK, RANGE_MOVE_PERMISSION_CHECK } from './const';