mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-11 23:26:30 +08:00
Merge pull request #329 from toeverything/feature-toc-optiscroll-mitsuha-dev
feature: 1.add primary ability in scroll scrollIntoViewByBlockId API;
This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
@@ -168,10 +167,6 @@ export const TOC = () => {
|
||||
}, [updateTocDataSource]);
|
||||
|
||||
const onClick = async (blockId?: string) => {
|
||||
if (blockId === activeBlockId) {
|
||||
return;
|
||||
}
|
||||
|
||||
setActiveBlockId(blockId);
|
||||
await editor.scrollManager.scrollIntoViewByBlockId(blockId);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { CSSProperties, type UIEvent } from 'react';
|
||||
import EventEmitter from 'eventemitter3';
|
||||
import { type UIEvent } from 'react';
|
||||
|
||||
import { domToRect, Rect } from '@toeverything/utils';
|
||||
import type { Editor as BlockEditor } from '../editor';
|
||||
@@ -164,22 +164,9 @@ export class ScrollManager {
|
||||
if (!block.dom) {
|
||||
return console.warn(`Block is not exist.`);
|
||||
}
|
||||
const containerRect = domToRect(this._scrollContainer);
|
||||
const blockRect = domToRect(block.dom);
|
||||
|
||||
const blockRelativeTopToEditor =
|
||||
blockRect.top - containerRect.top - containerRect.height / 4;
|
||||
const blockRelativeLeftToEditor = blockRect.left - containerRect.left;
|
||||
|
||||
this.scrollTo({
|
||||
left: blockRelativeLeftToEditor,
|
||||
top: blockRelativeTopToEditor,
|
||||
behavior,
|
||||
});
|
||||
this._updateScrollInfo(
|
||||
blockRelativeLeftToEditor,
|
||||
blockRelativeTopToEditor
|
||||
);
|
||||
/* use dom primary ability */
|
||||
block.dom.scrollIntoView({ block: 'start', behavior });
|
||||
}
|
||||
|
||||
public async keepBlockInView(
|
||||
|
||||
Reference in New Issue
Block a user