Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: code copy to clipboard

DiamondThree144a0f4af946
diff --git a/libs/components/editor-blocks/src/blocks/bullet/BulletView.tsx b/libs/components/editor-blocks/src/blocks/bullet/BulletView.tsx
index 143bebc0e2..6f1970df15 100644
--- a/libs/components/editor-blocks/src/blocks/bullet/BulletView.tsx
+++ b/libs/components/editor-blocks/src/blocks/bullet/BulletView.tsx
@@ -97,8 +97,12 @@ export const BulletView: FC<CreateView> = ({ block, editor }) => {
}
block.setProperty('numberType', getChildrenType(parentNumberType));
} catch (e) {
- // TODO
- console.log('undo redo bugfix');
+ console.warn(
+ 'Failed to update bullet list numbers!',
+ 'This issue may be related to the undo redo. block:',
+ block
+ );
+ console.warn(e);
}
};
diff --git a/libs/components/editor-blocks/src/blocks/code/CodeView.tsx b/libs/components/editor-blocks/src/blocks/code/CodeView.tsx
index b5e76b628b..3a729e51f0 100644
--- a/libs/components/editor-blocks/src/blocks/code/CodeView.tsx
+++ b/libs/components/editor-blocks/src/blocks/code/CodeView.tsx
@@ -52,6 +52,7 @@ import {
useOnSelect,
WrapperWithPendantAndDragDrop,
} from '@toeverything/components/editor-core';
+import { copyToClipboard } from '@toeverything/utils';
interface CreateCodeView extends CreateView {
style9?: StyleWithAtRules;
containerClassName?: string;
@@ -128,8 +129,8 @@ const CodeBlock = styled('div')(({ theme }) => ({
},
}));
export const CodeView: FC<CreateCodeView> = ({ block, editor }) => {
- const init_value: string = block.getProperty('text')?.value?.[0]?.text;
- const lang_type: string = block.getProperty('lang')?.value?.[0]?.text;
+ const initValue: string = block.getProperty('text')?.value?.[0]?.text;
+ const langType: string = block.getProperty('lang')?.value?.[0]?.text;
const [mode, setMode] = useState('javascript');
const [extensions, setExtensions] = useState<Extension[]>();
const codeMirror = useRef();
@@ -140,21 +141,20 @@ export const CodeView: FC<CreateCodeView> = ({ block, editor }) => {
}
});
const onChange = (value: any, codeEditor: any) => {
- console.log(value);
block.setProperty('text', {
value: [{ text: value }],
});
};
useEffect(() => {
- handleLangChange(lang_type ? lang_type : 'javascript');
+ handleLangChange(langType ? langType : 'javascript');
}, []);
function handleLangChange(lang: string) {
block.setProperty('lang', lang);
setMode(lang);
setExtensions([langs[lang]()]);
}
- const handle_remove_block = () => {
- block.remove();
+ const copyCode = () => {
+ copyToClipboard(initValue);
};
const handleKeyArrowDown = () => {
editor.selectionManager.activeNextNode(block.id, 'start');
@@ -197,10 +197,7 @@ export const CodeView: FC<CreateCodeView> = ({ block, editor }) => {
</Select>
</div>
<div>
- <div
- className="delete-block"
- // onClick={handle_remove_block}
- >
+ <div className="delete-block" onClick={copyCode}>
Copy
{/* <DeleteSweepOutlinedIcon
className="delete-icon"
@@ -217,7 +214,7 @@ export const CodeView: FC<CreateCodeView> = ({ block, editor }) => {
<CodeMirror
ref={codeMirror}
- value={init_value}
+ value={initValue}
height={'auto'}
extensions={extensions}
onChange={onChange}
diff --git a/libs/components/editor-core/src/editor/clipboard/clipboard-populator.ts b/libs/components/editor-core/src/editor/clipboard/clipboard-populator.ts
index d4f220009b..c110d57793 100644
--- a/libs/components/editor-core/src/editor/clipboard/clipboard-populator.ts
+++ b/libs/components/editor-core/src/editor/clipboard/clipboard-populator.ts
@@ -59,7 +59,6 @@ class ClipboardPopulator {
}
}
}
-
private copy_to_cliboard_from_pc(clips: any[]) {
let success = false;
const tempElem = document.createElement('textarea');
@@ -113,8 +112,7 @@ class ClipboardPopulator {
private async get_inner_clip(): Promise<InnerClipInfo> {
const clips: ClipBlockInfo[] = [];
- const select_info: SelectInfo =
- await this.selection_manager.getSelectInfo();
+ const select_info: SelectInfo = await this.selection_manager.getSelectInfo();
for (let i = 0; i < select_info.blocks.length; i++) {
const sel_block = select_info.blocks[i];
const clip_block_info = await this.get_clip_block_info(sel_block);