There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
chore(core): improve scroll anchoring (#8132)
fundond2cb7b76832e
diff --git a/packages/frontend/core/src/modules/editor/entities/editor.ts b/packages/frontend/core/src/modules/editor/entities/editor.tsindex b1b4afa8d4..eddb4dc8d8 100644--- a/packages/frontend/core/src/modules/editor/entities/editor.ts+++ b/packages/frontend/core/src/modules/editor/entities/editor.ts@@ -169,11 +169,10 @@ export class Editor extends Entity {get(this.mode$) === 'edgeless' && selector?.elementIds?.length? selector?.elementIds?.[0]: selector?.blockIds?.[0];- if (id) {- return { id, refreshKey: selector?.refreshKey };- } else {- return null;- }++ if (!id) return null;++ return { id, refreshKey: selector?.refreshKey };});if (focusAt$.value === null && docTitle) {const title = docTitle.querySelector<diff --git a/packages/frontend/core/src/modules/editor/utils/scroll-anchoring.ts b/packages/frontend/core/src/modules/editor/utils/scroll-anchoring.tsindex 6fc06a0378..8f51ea23ee 100644--- a/packages/frontend/core/src/modules/editor/utils/scroll-anchoring.ts+++ b/packages/frontend/core/src/modules/editor/utils/scroll-anchoring.ts@@ -1,9 +1,10 @@-import type { BlockStdScope } from '@blocksuite/block-std';+import type { BlockStdScope, SelectionManager } from '@blocksuite/block-std';import type {DocMode,EdgelessRootService,PageRootService,} from '@blocksuite/blocks';+import { ZOOM_MAX } from '@blocksuite/blocks';import { Bound, deserializeXYWH } from '@blocksuite/global/utils';function scrollAnchoringInEdgelessMode(@@ -11,23 +12,14 @@ function scrollAnchoringInEdgelessMode(id: string) {requestAnimationFrame(() => {- let isNotInNote = true;let bounds: Bound | null = null;+ let pageSelection: SelectionManager | null = null;const blockComponent = service.std.view.getBlock(id);-const parentComponent = blockComponent?.parentComponent;if (parentComponent && parentComponent.flavour === 'affine:note') {- isNotInNote = false;-- const selection = parentComponent.std.selection;- if (!selection) return;-- selection.set([- selection.create('block', {- blockId: id,- }),- ]);+ pageSelection = parentComponent.std.selection;+ if (!pageSelection) return;const { left: x, width: w } = parentComponent.getBoundingClientRect();const { top: y, height: h } = blockComponent.getBoundingClientRect();@@ -48,20 +40,28 @@ function scrollAnchoringInEdgelessMode(if (!bounds) return;- if (isNotInNote) {+ const { zoom, centerX, centerY } = service.getFitToScreenData(+ [20, 20, 100, 20],+ [bounds],+ ZOOM_MAX+ );++ service.viewport.setCenter(centerX, centerY);+ service.viewport.setZoom(zoom);++ if (pageSelection) {+ pageSelection.setGroup('note', [+ pageSelection.create('block', {+ blockId: id,+ }),+ ]);+ } else {service.selection.set({elements: [id],editing: false,});}- const { zoom, centerX, centerY } = service.getFitToScreenData(- [20, 20, 20, 20],- [bounds]- );-- service.viewport.setViewport(zoom, [centerX, centerY]);-// const surfaceComponent = service.std.view.getBlock(service.surface.id);// if (!surfaceComponent) return;// (surfaceComponent as SurfaceBlockComponent).refresh();@@ -82,7 +82,7 @@ function scrollAnchoringInPageMode(service: PageRootService, id: string) {const selection = service.std.selection;if (!selection) return;- selection.set([+ selection.setGroup('note', [selection.create('block', {blockId: id,}),