mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-30 05:34:21 +03:00
fix(core): block sharing link cannot be created when selecting inline (#7090)
This commit is contained in:
parent
d43fcdcdd6
commit
412b919ec6
@ -1,5 +1,9 @@
|
||||
import { ViewService } from '@affine/core/modules/workbench/services/view';
|
||||
import type { BaseSelection, BlockElement } from '@blocksuite/block-std';
|
||||
import type {
|
||||
BaseSelection,
|
||||
BlockElement,
|
||||
TextSelection,
|
||||
} from '@blocksuite/block-std';
|
||||
import type { Disposable } from '@blocksuite/global/utils';
|
||||
import type {
|
||||
AffineEditorContainer,
|
||||
@ -102,6 +106,7 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
ref
|
||||
) {
|
||||
const scrolledRef = useRef(false);
|
||||
const hashChangedRef = useRef(false);
|
||||
const rootRef = useRef<HTMLDivElement>(null);
|
||||
const docRef = useRef<PageEditor>(null);
|
||||
const edgelessRef = useRef<EdgelessEditor>(null);
|
||||
@ -231,7 +236,12 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
};
|
||||
affineEditorContainerProxy.updateComplete
|
||||
.then(() => {
|
||||
if (blockElement && !scrolledRef.current && !canceled) {
|
||||
if (
|
||||
blockElement &&
|
||||
!scrolledRef.current &&
|
||||
!canceled &&
|
||||
!hashChangedRef.current
|
||||
) {
|
||||
handleScrollToBlock(blockElement);
|
||||
scrolledRef.current = true;
|
||||
}
|
||||
@ -258,14 +268,24 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (selection[0]?.type !== 'block') {
|
||||
if (mode === 'edgeless') {
|
||||
if (locationHash) {
|
||||
// Clear the hash if no block is selected
|
||||
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;
|
||||
@ -274,9 +294,11 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
|
||||
// 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;
|
||||
@ -290,7 +312,7 @@ export const BlocksuiteEditorContainer = forwardRef<
|
||||
canceled = true;
|
||||
disposable?.dispose();
|
||||
};
|
||||
}, [affineEditorContainerProxy, currentView]);
|
||||
}, [affineEditorContainerProxy, currentView, mode]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
Loading…
Reference in New Issue
Block a user