Skip to content

Commit

Permalink
减少看不懂的计算
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Nov 21, 2024
1 parent 716db8f commit cc5cd43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
31 changes: 11 additions & 20 deletions src/MarkdownEditor/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ import { useStyle } from './style';
import { isMarkdown } from './utils';
import { getMediaType } from './utils/dom';
import {
calcPath,
EditorUtils,
findLeafPath,
getRelativePath,
getSelectionFromDomSelection,
hasEditableTarget,
isEventHandled,
Expand Down Expand Up @@ -92,10 +90,10 @@ export const MEditor = observer(
} catch (e) {
EditorUtils.deleteAll(editor);
}
requestIdleCallback(() => {
setTimeout(() => {
store.initializing = false;
store.setState((state) => (state.pauseCodeHighlight = false));
});
}, 10);
} else {
nodeRef.current = undefined;
}
Expand Down Expand Up @@ -545,37 +543,30 @@ export const MEditor = observer(
const [, path] = e;
const itemMap = commentMap.get(path.join(','));
if (!itemMap) return decorateList;
let newPath = path;
if (Array.isArray(path) && path[path.length - 1] !== 0) {
newPath = [...path, 0];
}
itemMap.forEach((itemList) => {
const item = itemList[0];
const { anchor, focus } = item.selection || {};
if (!anchor || !focus) return decorateList;
const relativePath = getRelativePath(newPath, anchor.path);
const AnchorPath = calcPath(anchor.path, relativePath);
const FocusPath = calcPath(focus.path, relativePath);
const AnchorPath = anchor.path;
const FocusPath = focus.path;

if (
isPath(FocusPath) &&
isPath(AnchorPath) &&
Editor.hasPath(editor, AnchorPath) &&
Editor.hasPath(editor, FocusPath)
Editor.hasPath(editor, anchor.path) &&
Editor.hasPath(editor, focus.path)
) {
console.log(findLeafPath(editor, AnchorPath));
const newSelection = {
anchor: { ...anchor, path: findLeafPath(editor, AnchorPath) },
focus: { ...focus, path: findLeafPath(editor, FocusPath) },
};

const fragement = Editor.fragment(editor, newSelection);
if (fragement) {
const str = Node.string({ children: fragement });
const fragment = Editor.fragment(editor, newSelection);
if (fragment) {
const str = Node.string({ children: fragment });
const isStrEquals = str === item.refContent;
const relativePath = getRelativePath(newPath, anchor.path);
const newAnchorPath = calcPath(anchor.path, relativePath);
const newFocusPath = calcPath(focus.path, relativePath);
const newAnchorPath = anchor.path;
const newFocusPath = focus.path;

if (
isStrEquals &&
Expand Down
2 changes: 1 addition & 1 deletion src/MarkdownEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export type CommentDataType = {
refContent: string;
commentType: string;
content: string;
time: number;
time: number | string;
id: string | number;
user?: {
name: string;
Expand Down

1 comment on commit cc5cd43

@vercel
Copy link

@vercel vercel bot commented on cc5cd43 Nov 21, 2024

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.