mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 10:45:57 +08:00
fix: #547
This commit is contained in:
@@ -46,24 +46,24 @@ const BulletLeft = styled('div')(() => ({
|
|||||||
export const BulletView: FC<CreateView> = ({ block, editor }) => {
|
export const BulletView: FC<CreateView> = ({ block, editor }) => {
|
||||||
// block.remove();
|
// block.remove();
|
||||||
const properties = { ...defaultBulletProps, ...block.getProperties() };
|
const properties = { ...defaultBulletProps, ...block.getProperties() };
|
||||||
const text_ref = useRef<ExtendedTextUtils>(null);
|
const textRef = useRef<ExtendedTextUtils>(null);
|
||||||
// const [type, set_type] = useState('type-1');
|
// const [type, set_type] = useState('type-1');
|
||||||
const [isSelect, setIsSelect] = useState<boolean>();
|
const [isSelect, setIsSelect] = useState<boolean>();
|
||||||
|
|
||||||
useOnSelect(block.id, (is_select: boolean) => {
|
useOnSelect(block.id, (is_select: boolean) => {
|
||||||
setIsSelect(is_select);
|
setIsSelect(is_select);
|
||||||
});
|
});
|
||||||
const turn_into_text_block = async () => {
|
const turnIntoTextBlock = async () => {
|
||||||
// Convert to text block
|
// Convert to text block
|
||||||
await block.setType('text');
|
await block.setType('text');
|
||||||
await reset_todo_state(block);
|
await reset_todo_state(block);
|
||||||
|
|
||||||
if (!text_ref.current) {
|
if (!textRef.current) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Failed to set cursor position! text_ref is not exist!'
|
'Failed to set cursor position! text_ref is not exist!'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const currentSelection = text_ref.current.getStartSelection();
|
const currentSelection = textRef.current.getStartSelection();
|
||||||
if (!currentSelection) {
|
if (!currentSelection) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Failed to get cursor selection! currentSelection is not exist!'
|
'Failed to get cursor selection! currentSelection is not exist!'
|
||||||
@@ -82,28 +82,35 @@ export const BulletView: FC<CreateView> = ({ block, editor }) => {
|
|||||||
};
|
};
|
||||||
const i = 0;
|
const i = 0;
|
||||||
const listChange = async () => {
|
const listChange = async () => {
|
||||||
const preBlock = await block.previousSiblings();
|
try {
|
||||||
const parent_block = await block.parent();
|
const parentBlock = await block.parent();
|
||||||
let parent_number_type = parent_block.getProperty('numberType');
|
if (!parentBlock) {
|
||||||
if (
|
return;
|
||||||
!parent_number_type &&
|
}
|
||||||
parent_block.type === Protocol.Block.Type.bullet
|
let parentNumberType = parentBlock.getProperty('numberType');
|
||||||
) {
|
if (
|
||||||
parent_number_type = NumberType.type1;
|
!parentNumberType &&
|
||||||
parent_block.setProperty('numberType', parent_number_type);
|
parentBlock.type === Protocol.Block.Type.bullet
|
||||||
|
) {
|
||||||
|
parentNumberType = NumberType.type1;
|
||||||
|
parentBlock.setProperty('numberType', parentNumberType);
|
||||||
|
}
|
||||||
|
block.setProperty('numberType', getChildrenType(parentNumberType));
|
||||||
|
} catch (e) {
|
||||||
|
// TODO
|
||||||
|
console.log('undo redo bugfix');
|
||||||
}
|
}
|
||||||
block.setProperty('numberType', getChildrenType(parent_number_type));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
listChange();
|
listChange();
|
||||||
let obj: any;
|
let obj: any;
|
||||||
const parentChange = async () => {
|
const parentChange = async () => {
|
||||||
const parent_block = await block.parent();
|
const parentBlock = await block.parent();
|
||||||
obj = await services.api.editorBlock.observe(
|
obj = await services.api.editorBlock.observe(
|
||||||
{
|
{
|
||||||
workspace: editor.workspace,
|
workspace: editor.workspace,
|
||||||
id: parent_block.id,
|
id: parentBlock.id,
|
||||||
},
|
},
|
||||||
listChange
|
listChange
|
||||||
);
|
);
|
||||||
@@ -115,16 +122,16 @@ export const BulletView: FC<CreateView> = ({ block, editor }) => {
|
|||||||
// console.log('_parent_block: ', _parent_block);
|
// console.log('_parent_block: ', _parent_block);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const on_text_enter: TextProps['handleEnter'] = async props => {
|
const onTextEnter: TextProps['handleEnter'] = async props => {
|
||||||
const { splitContents, isShiftKey } = props;
|
const { splitContents, isShiftKey } = props;
|
||||||
if (isShiftKey) {
|
if (isShiftKey) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const { contentBeforeSelection, contentAfterSelection } = splitContents;
|
const { contentBeforeSelection, contentAfterSelection } = splitContents;
|
||||||
const before = [...contentBeforeSelection.content];
|
const before = [...(contentBeforeSelection.content ?? '')];
|
||||||
const after = [...contentAfterSelection.content];
|
const after = [...(contentAfterSelection.content ?? '')];
|
||||||
if (todoIsEmpty({ value: before } as ContentColumnValue)) {
|
if (todoIsEmpty({ value: before } as ContentColumnValue)) {
|
||||||
await turn_into_text_block();
|
await turnIntoTextBlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,15 +156,15 @@ export const BulletView: FC<CreateView> = ({ block, editor }) => {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
const on_tab: TextProps['handleTab'] = async ({ isShiftKey }) => {
|
const onTab: TextProps['handleTab'] = async ({ isShiftKey }) => {
|
||||||
if (!isShiftKey) {
|
if (!isShiftKey) {
|
||||||
const preSiblingBlock = await block.previousSibling();
|
const preSiblingBlock = await block.previousSibling();
|
||||||
if (preSiblingBlock && supportChildren(preSiblingBlock)) {
|
if (preSiblingBlock && supportChildren(preSiblingBlock)) {
|
||||||
const copy_block = block;
|
const copyBlock = block;
|
||||||
block.remove();
|
block.remove();
|
||||||
block.removeChildren();
|
block.removeChildren();
|
||||||
const block_children = await copy_block.children();
|
const blockChildren = await copyBlock.children();
|
||||||
preSiblingBlock.append(copy_block, ...block_children);
|
preSiblingBlock.append(copyBlock, ...blockChildren);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -165,13 +172,13 @@ export const BulletView: FC<CreateView> = ({ block, editor }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const on_backspace: TextProps['handleBackSpace'] = async ({
|
const onBackspace: TextProps['handleBackSpace'] = async ({
|
||||||
isCollAndStart,
|
isCollAndStart,
|
||||||
}) => {
|
}) => {
|
||||||
if (!isCollAndStart) {
|
if (!isCollAndStart) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await turn_into_text_block();
|
await turnIntoTextBlock();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -184,14 +191,14 @@ export const BulletView: FC<CreateView> = ({ block, editor }) => {
|
|||||||
</BulletLeft>
|
</BulletLeft>
|
||||||
<div className={'textContainer'}>
|
<div className={'textContainer'}>
|
||||||
<TextManage
|
<TextManage
|
||||||
ref={text_ref}
|
ref={textRef}
|
||||||
editor={editor}
|
editor={editor}
|
||||||
block={block}
|
block={block}
|
||||||
supportMarkdown
|
supportMarkdown
|
||||||
placeholder="/Bullet list"
|
placeholder="/Bullet list"
|
||||||
handleEnter={on_text_enter}
|
handleEnter={onTextEnter}
|
||||||
handleBackSpace={on_backspace}
|
handleBackSpace={onBackspace}
|
||||||
handleTab={on_tab}
|
handleTab={onTab}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</List>
|
</List>
|
||||||
|
|||||||
Reference in New Issue
Block a user