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.

feat: make scroll by bar to be operations for liveshare (#773)

YuHong86b803cb0fd9
diff --git a/packages/engine-render/src/shape/scroll-bar.ts b/packages/engine-render/src/shape/scroll-bar.ts
index 3798116717..02bf4495c4 100644
--- a/packages/engine-render/src/shape/scroll-bar.ts
+++ b/packages/engine-render/src/shape/scroll-bar.ts
@@ -364,7 +364,7 @@ export class ScrollBar extends BaseScrollBar {
if (!this._isVerticalMove) {
return;
}
- this._view.scrollBy({
+ this._view.scrollByBar({
y: e.offsetY - this._lastY,
});
this._lastY = e.offsetY;
@@ -443,7 +443,7 @@ export class ScrollBar extends BaseScrollBar {
if (!this._isHorizonMove) {
return;
}
- this._view.scrollBy({
+ this._view.scrollByBar({
x: e.offsetX - this._lastX,
});
this._lastX = e.offsetX;
diff --git a/packages/engine-render/src/viewport.ts b/packages/engine-render/src/viewport.ts
index 0b6487a996..4b6d1500fc 100644
--- a/packages/engine-render/src/viewport.ts
+++ b/packages/engine-render/src/viewport.ts
@@ -94,6 +94,8 @@ export class Viewport {
onScrollStopObserver = new Observable<IScrollObserverParam>();
+ onScrollByBarObserver = new Observable<IScrollObserverParam>();
+
private _viewPortKey: string = '';
private _dirty: boolean = true;
@@ -380,6 +382,10 @@ export class Viewport {
return this._scroll(SCROLL_TYPE.scrollBy, pos, isTrigger);
}
+ scrollByBar(pos: IScrollBarPosition, isTrigger = true) {
+ this._scroll(SCROLL_TYPE.scrollBy, pos, isTrigger, true);
+ }
+
/**
* current position plus offset relatively
* the caller no need to deal with the padding when frozen
@@ -865,7 +871,7 @@ export class Viewport {
}, 0);
}
- private _scroll(scrollType: SCROLL_TYPE, pos: IScrollBarPosition, isTrigger = true) {
+ private _scroll(scrollType: SCROLL_TYPE, pos: IScrollBarPosition, isTrigger = true, isFromBar = false) {
const { x, y } = pos;
if (this._scrollBar == null) {
@@ -932,6 +938,21 @@ export class Viewport {
isTrigger,
});
+ if (isFromBar) {
+ this.onScrollByBarObserver.notifyObservers({
+ viewport: this,
+ scrollX: this.scrollX,
+ scrollY: this.scrollY,
+ x,
+ y,
+ actualScrollX: scroll.x,
+ actualScrollY: scroll.y,
+ limitX: this._scrollBar?.limitX,
+ limitY: this._scrollBar?.limitY,
+ isTrigger,
+ });
+ }
+
this._triggerScrollStop(scroll, x, y, isTrigger);
return limited;
diff --git a/packages/sheets-ui/src/controllers/scroll.controller.ts b/packages/sheets-ui/src/controllers/scroll.controller.ts
index edc48fa245..907b21903d 100644
--- a/packages/sheets-ui/src/controllers/scroll.controller.ts
+++ b/packages/sheets-ui/src/controllers/scroll.controller.ts
@@ -97,6 +97,33 @@ export class ScrollController extends Disposable {
})
)
);
+ this.disposeWithMe(
+ toDisposable(
+ viewportMain?.onScrollByBarObserver.add((param) => {
+ const skeleton = this._sheetSkeletonManagerService.getCurrent()?.skeleton;
+ if (skeleton == null || param.isTrigger === false) {
+ return;
+ }
+
+ const sheetObject = this._getSheetObject();
+ if (skeleton == null || sheetObject == null) {
+ return;
+ }
+ const { actualScrollX = 0, actualScrollY = 0 } = param;
+ // according to the actual scroll position, the most suitable row, column and offset combination is recalculated.
+ const { row, column, rowOffset, columnOffset } = skeleton.getDecomposedOffset(
+ actualScrollX,
+ actualScrollY
+ );
+ this._commandService.executeCommand(ScrollCommand.id, {
+ sheetViewStartRow: row,
+ sheetViewStartColumn: column,
+ offsetX: columnOffset,
+ offsetY: rowOffset,
+ });
+ })
+ )
+ );
}
scrollToVisible(direction: Direction) {