Skip to content

Commit

Permalink
feat: 优化Markdown编辑器的元素样式,增强复制功能的错误处理
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Feb 18, 2025
1 parent 96848bc commit e515a02
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
15 changes: 12 additions & 3 deletions src/MarkdownEditor/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Editor,
Element,
Node,
Path,
Range,
Transforms,
} from 'slate';
Expand Down Expand Up @@ -315,6 +316,11 @@ export const MEditor = observer(
}
const selection =
markdownEditorRef.current?.selection?.focus?.path;
const node = Node.get(
markdownEditorRef.current,
Path.parent(selection!)!,
);

const at = selection
? EditorUtils.findNext(markdownEditorRef.current, selection)!
: undefined;
Expand All @@ -326,9 +332,12 @@ export const MEditor = observer(
EditorUtils.createMediaNode(u, 'image'),
{
at: [
at
? at[0]
: markdownEditorRef.current.children.length - 1,
...(node.type === 'table-cell' ||
node.type === 'column-cell'
? selection!
: at
? at
: [markdownEditorRef.current.children.length - 1]),
],
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/MarkdownEditor/editor/elements/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const WarpCard = observer((props: RenderElementProps) => {
data-be={'card'}
style={{
display: 'flex',
gap: 1,
gap: 4,
maxWidth: '100%',
}}
>
Expand Down
4 changes: 4 additions & 0 deletions src/MarkdownEditor/editor/elements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ export const MElement = (
style={{
minWidth: 4,
height: '100%',
fontWeight: 800,
position: 'relative',
zIndex: 99,
fontSize: '2em',
display: props.readonly ? 'none' : 'block',
}}
data-be={'card-before'}
Expand All @@ -128,6 +130,8 @@ export const MElement = (
alignSelf: 'end',
position: 'relative',
zIndex: 99,

fontSize: '2em',
display: props.readonly ? 'none' : 'block',
}}
data-be={'card-after'}
Expand Down
6 changes: 4 additions & 2 deletions src/MarkdownEditor/editor/tools/ToolBar/ReadonlyBaseBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ export const ReadonlyBaseBar = observer(
for (const str of texts) {
title += str;
}
navigator.clipboard.writeText(title);
message.success('Copy Success');
try {
navigator.clipboard.writeText(title);
message.success('Copy Success');
} catch (error) {}
}}
>
<span>
Expand Down
9 changes: 7 additions & 2 deletions src/MarkdownEditor/editor/utils/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,15 +798,20 @@ export const useSystemKeyboard = (
const url = `media://file?url=${readlUrl}&height=${
node[0].height || ''
}`;
navigator.clipboard.writeText(url);
try {
navigator.clipboard.writeText(url);
} catch (error) {}
if (isHotkey('mod+x', e)) {
Transforms.delete(store?.editor, { at: node[1] });
ReactEditor.focus(store?.editor);
}
}
if (node[0].type === 'attach') {
const url = `attach://file?size=${node[0].size}&name=${node[0].name}&url=${node[0]?.url}`;
navigator.clipboard.writeText(url);
try {
navigator.clipboard.writeText(url);
} catch (error) {}

if (isHotkey('mod+x', e)) {
Transforms.delete(store?.editor, { at: node[1] });
ReactEditor.focus(store?.editor);
Expand Down

1 comment on commit e515a02

@vercel
Copy link

@vercel vercel bot commented on e515a02 Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.