fix(core): block sharing link cannot be created when selecting inline (#7090)
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
import { ViewService } from '@affine/core/modules/workbench/services/view';
|
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 { Disposable } from '@blocksuite/global/utils';
|
||||||
import type {
|
import type {
|
||||||
AffineEditorContainer,
|
AffineEditorContainer,
|
||||||
@@ -102,6 +106,7 @@ export const BlocksuiteEditorContainer = forwardRef<
|
|||||||
ref
|
ref
|
||||||
) {
|
) {
|
||||||
const scrolledRef = useRef(false);
|
const scrolledRef = useRef(false);
|
||||||
|
const hashChangedRef = useRef(false);
|
||||||
const rootRef = useRef<HTMLDivElement>(null);
|
const rootRef = useRef<HTMLDivElement>(null);
|
||||||
const docRef = useRef<PageEditor>(null);
|
const docRef = useRef<PageEditor>(null);
|
||||||
const edgelessRef = useRef<EdgelessEditor>(null);
|
const edgelessRef = useRef<EdgelessEditor>(null);
|
||||||
@@ -231,7 +236,12 @@ export const BlocksuiteEditorContainer = forwardRef<
|
|||||||
};
|
};
|
||||||
affineEditorContainerProxy.updateComplete
|
affineEditorContainerProxy.updateComplete
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (blockElement && !scrolledRef.current && !canceled) {
|
if (
|
||||||
|
blockElement &&
|
||||||
|
!scrolledRef.current &&
|
||||||
|
!canceled &&
|
||||||
|
!hashChangedRef.current
|
||||||
|
) {
|
||||||
handleScrollToBlock(blockElement);
|
handleScrollToBlock(blockElement);
|
||||||
scrolledRef.current = true;
|
scrolledRef.current = true;
|
||||||
}
|
}
|
||||||
@@ -258,14 +268,24 @@ export const BlocksuiteEditorContainer = forwardRef<
|
|||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (selection[0]?.type !== 'block') {
|
if (mode === 'edgeless') {
|
||||||
if (locationHash) {
|
if (locationHash) {
|
||||||
// Clear the hash if no block is selected
|
|
||||||
currentView.replace(currentPath);
|
currentView.replace(currentPath);
|
||||||
}
|
}
|
||||||
return;
|
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;
|
const selectedId = selection[0]?.blockId;
|
||||||
if (!selectedId) {
|
if (!selectedId) {
|
||||||
return;
|
return;
|
||||||
@@ -274,9 +294,11 @@ export const BlocksuiteEditorContainer = forwardRef<
|
|||||||
|
|
||||||
// Only update the hash if it has changed
|
// Only update the hash if it has changed
|
||||||
if (locationHash !== newHash) {
|
if (locationHash !== newHash) {
|
||||||
|
hashChangedRef.current = true;
|
||||||
currentView.replace(currentPath + newHash);
|
currentView.replace(currentPath + newHash);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
affineEditorContainerProxy.updateComplete
|
affineEditorContainerProxy.updateComplete
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const selectManager = affineEditorContainerProxy.host?.selection;
|
const selectManager = affineEditorContainerProxy.host?.selection;
|
||||||
@@ -290,7 +312,7 @@ export const BlocksuiteEditorContainer = forwardRef<
|
|||||||
canceled = true;
|
canceled = true;
|
||||||
disposable?.dispose();
|
disposable?.dispose();
|
||||||
};
|
};
|
||||||
}, [affineEditorContainerProxy, currentView]);
|
}, [affineEditorContainerProxy, currentView, mode]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user