mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-08 12:45:55 +08:00
refactor(core): remove the automatic URL change feature (#7339)
close [AF-954](https://linear.app/affine-design/issue/AF-954/center-peek-中-editor-selection-变化不应修改-location-hash) Since the URL changes constantly with the selection, causing the editor to render frequently and also affecting the use of center peek, we decided to remove the function of automatically changing the URL.
This commit is contained in:
+2
-72
@@ -1,10 +1,4 @@
|
||||
import { ViewService } from '@affine/core/modules/workbench/services/view';
|
||||
import type {
|
||||
BaseSelection,
|
||||
BlockElement,
|
||||
TextSelection,
|
||||
} from '@blocksuite/block-std';
|
||||
import type { Disposable } from '@blocksuite/global/utils';
|
||||
import type { BlockElement } from '@blocksuite/block-std';
|
||||
import type {
|
||||
AffineEditorContainer,
|
||||
EdgelessEditor,
|
||||
@@ -12,7 +6,7 @@ import type {
|
||||
} from '@blocksuite/presets';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import { Slot } from '@blocksuite/store';
|
||||
import { type DocMode, useServiceOptional } from '@toeverything/infra';
|
||||
import { type DocMode } from '@toeverything/infra';
|
||||
import clsx from 'clsx';
|
||||
import type React from 'react';
|
||||
import type { RefObject } from 'react';
|
||||
@@ -111,7 +105,6 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
const rootRef = useRef<HTMLDivElement>(null);
|
||||
const docRef = useRef<PageEditor>(null);
|
||||
const edgelessRef = useRef<EdgelessEditor>(null);
|
||||
const renderStartRef = useRef<number>(Date.now());
|
||||
|
||||
const slots: BlocksuiteEditorContainerRef['slots'] = useMemo(() => {
|
||||
return {
|
||||
@@ -214,7 +207,6 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
}, [affineEditorContainerProxy, ref]);
|
||||
|
||||
const blockElement = useBlockElementById(rootRef, defaultSelectedBlockId);
|
||||
const currentView = useServiceOptional(ViewService)?.view;
|
||||
|
||||
useEffect(() => {
|
||||
let canceled = false;
|
||||
@@ -253,68 +245,6 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
};
|
||||
}, [blockElement, affineEditorContainerProxy, mode]);
|
||||
|
||||
useEffect(() => {
|
||||
let disposable: Disposable | null = null;
|
||||
let canceled = false;
|
||||
// Function to handle block selection change
|
||||
const handleSelectionChange = (selection: BaseSelection[]) => {
|
||||
const viewLocation = currentView?.location$.value;
|
||||
const currentPath = viewLocation?.pathname;
|
||||
const locationHash = viewLocation?.hash;
|
||||
if (
|
||||
!currentView ||
|
||||
!currentPath ||
|
||||
// do not update the hash during the initial render
|
||||
renderStartRef.current > Date.now() - 1000
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (mode === 'edgeless') {
|
||||
if (locationHash) {
|
||||
currentView.replace(currentPath);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (selection[0]?.type === 'text') {
|
||||
const textSelection = selection[0] as TextSelection;
|
||||
if (textSelection.from.length === 0) {
|
||||
// Clear the hash if no block is selected
|
||||
if (locationHash) {
|
||||
currentView.replace(currentPath);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const selectedId = selection[0]?.blockId;
|
||||
if (!selectedId) {
|
||||
return;
|
||||
}
|
||||
const newHash = `#${selectedId}`;
|
||||
|
||||
// Only update the hash if it has changed
|
||||
if (locationHash !== newHash) {
|
||||
hashChangedRef.current = true;
|
||||
currentView.replace(currentPath + newHash);
|
||||
}
|
||||
};
|
||||
|
||||
affineEditorContainerProxy.updateComplete
|
||||
.then(() => {
|
||||
const selectManager = affineEditorContainerProxy.host?.selection;
|
||||
if (!selectManager || canceled) return;
|
||||
// Set up the new disposable listener
|
||||
disposable = selectManager.slots.changed.on(handleSelectionChange);
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
return () => {
|
||||
canceled = true;
|
||||
disposable?.dispose();
|
||||
};
|
||||
}, [affineEditorContainerProxy, currentView, mode]);
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid={`editor-${page.id}`}
|
||||
|
||||
Reference in New Issue
Block a user