mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-23 00:11:33 +03:00
feat: Intra-line double link interaction
This commit is contained in:
parent
dd1b160ef4
commit
2406f9556f
@ -597,10 +597,11 @@ class SlateUtils {
|
||||
|
||||
const fragmentChildren = firstFragment.children;
|
||||
|
||||
const textChildren: Text[] = [];
|
||||
for (const child of fragmentChildren) {
|
||||
if ((child as any).type === 'link') {
|
||||
textChildren.push(child as Text);
|
||||
const textChildren = [];
|
||||
for (let i = 0; i < fragmentChildren.length; i++) {
|
||||
const child = fragmentChildren[i];
|
||||
if ('type' in child && child.type === 'link') {
|
||||
i !== fragmentChildren.length - 1 && textChildren.push(child);
|
||||
continue;
|
||||
}
|
||||
if (!('text' in child)) {
|
||||
|
@ -508,21 +508,19 @@ export class AsyncBlock {
|
||||
id: item.blockId,
|
||||
});
|
||||
|
||||
if (linkBlock) {
|
||||
let children = linkBlock.getProperties().text?.value || [];
|
||||
if (children.length === 1 && !children[0].text) {
|
||||
children = [{ text: 'Untitled' }];
|
||||
}
|
||||
if (
|
||||
children.map(v => v.text).join('') !==
|
||||
(item.children || []).map((v: any) => v.text).join('')
|
||||
) {
|
||||
const newItem = {
|
||||
...item,
|
||||
children: children,
|
||||
};
|
||||
values.splice(i, 1, newItem);
|
||||
}
|
||||
let children = linkBlock?.getProperties().text?.value || [];
|
||||
if (children.length === 1 && !children[0].text) {
|
||||
children = [{ text: 'Untitled' }];
|
||||
}
|
||||
if (
|
||||
children.map(v => v.text).join('') !==
|
||||
(item.children || []).map((v: any) => v.text).join('')
|
||||
) {
|
||||
const newItem = {
|
||||
...item,
|
||||
children: children,
|
||||
};
|
||||
values.splice(i, 1, newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +135,44 @@ export const DoubleLinkMenu = ({
|
||||
editor.scrollManager.unLock();
|
||||
}, [curBlockId, editor]);
|
||||
|
||||
const resetState = useCallback(
|
||||
(preNodeId: string, nextNodeId: string) => {
|
||||
editor.blockHelper.removeDoubleLinkSearchSlash(preNodeId);
|
||||
setCurBlockId(nextNodeId);
|
||||
setSearchText('');
|
||||
setIsOpen(true);
|
||||
editor.scrollManager.lock();
|
||||
const clientRect =
|
||||
editor.selection.currentSelectInfo?.browserSelection
|
||||
?.getRangeAt(0)
|
||||
?.getBoundingClientRect();
|
||||
if (clientRect) {
|
||||
const rectTop = clientRect.top;
|
||||
const { top, left } = editor.container.getBoundingClientRect();
|
||||
setDoubleLinkMenuStyle({
|
||||
top: rectTop - top,
|
||||
left: clientRect.left - left,
|
||||
height: clientRect.height,
|
||||
});
|
||||
setAnchorEl(dialogRef.current);
|
||||
}
|
||||
setTimeout(() => {
|
||||
const textSelection = editor.blockHelper.selectionToSlateRange(
|
||||
nextNodeId,
|
||||
editor.selection.currentSelectInfo.browserSelection
|
||||
);
|
||||
if (textSelection) {
|
||||
const { anchor } = textSelection;
|
||||
editor.blockHelper.setDoubleLinkSearchSlash(
|
||||
nextNodeId,
|
||||
anchor
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
[editor]
|
||||
);
|
||||
|
||||
const searchChange = useCallback(
|
||||
async (event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||
if (ARRAY_CODES.includes(event.code)) {
|
||||
@ -162,41 +200,7 @@ export const DoubleLinkMenu = ({
|
||||
anchorNode.id
|
||||
);
|
||||
if (text.endsWith('[[')) {
|
||||
editor.blockHelper.removeDoubleLinkSearchSlash(curBlockId);
|
||||
setCurBlockId(anchorNode.id);
|
||||
setSearchText('');
|
||||
setIsOpen(true);
|
||||
editor.scrollManager.lock();
|
||||
const clientRect =
|
||||
editor.selection.currentSelectInfo?.browserSelection
|
||||
?.getRangeAt(0)
|
||||
?.getBoundingClientRect();
|
||||
if (clientRect) {
|
||||
const rectTop = clientRect.top;
|
||||
const { top, left } =
|
||||
editor.container.getBoundingClientRect();
|
||||
setDoubleLinkMenuStyle({
|
||||
top: rectTop - top,
|
||||
left: clientRect.left - left,
|
||||
height: clientRect.height,
|
||||
});
|
||||
setAnchorEl(dialogRef.current);
|
||||
}
|
||||
setTimeout(() => {
|
||||
const textSelection =
|
||||
editor.blockHelper.selectionToSlateRange(
|
||||
anchorNode.id,
|
||||
editor.selection.currentSelectInfo
|
||||
.browserSelection
|
||||
);
|
||||
if (textSelection) {
|
||||
const { anchor } = textSelection;
|
||||
editor.blockHelper.setDoubleLinkSearchSlash(
|
||||
anchorNode.id,
|
||||
anchor
|
||||
);
|
||||
}
|
||||
});
|
||||
resetState(curBlockId, anchorNode.id);
|
||||
}
|
||||
}
|
||||
if (isOpen) {
|
||||
@ -372,7 +376,6 @@ export const DoubleLinkMenu = ({
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const NewPageSearchContainer = styled('div')({
|
||||
padding: '8px 8px 0px 8px',
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user