Skip to content

Commit

Permalink
Merge pull request #2 from mc-favorite-tools/feat/1.20+
Browse files Browse the repository at this point in the history
fix: first node lack of \n
  • Loading branch information
hans000 authored Jun 1, 2024
2 parents bc72366 + de99c02 commit 79bb1d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
15 changes: 6 additions & 9 deletions src/components/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import { MarkNode } from '@lexical/mark';
import JsonTablePlugin from './plugins/JsonTablePlugin';
import ObfuscatedPlugin from './plugins/ObfuscatedPlugin';
import { Slider } from 'antd';
import { useContext, useEffect, useState } from 'react';
import { useContext, useState } from 'react';
import { AppContext } from '../../store';
import { $getRoot } from 'lexical';
import HorizontalRulePlugin from './plugins/HorizontalRulePlugin';
import { HorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';

Expand All @@ -36,12 +35,6 @@ const Wrapper = styled.div`
}
`

function onChange(editorState: any) {
editorState.read(() => {

})
}

export function Editor() {
const [state, dispatch] = useContext(AppContext)
const [visible, setVisible] = useState(false)
Expand Down Expand Up @@ -73,7 +66,11 @@ export function Editor() {
}} />}
placeholder={''}
/>
<OnChangePlugin onChange={onChange} />
<OnChangePlugin onChange={(editorState) => {
editorState.read(() => {

})
}} />
<CommentPlugin />
<HistoryPlugin />
<ObfuscatedPlugin />
Expand Down
26 changes: 13 additions & 13 deletions src/components/editor/plugins/ToolbarPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,19 +416,19 @@ export default function ToolbarPlugin(props: {

// 处理边缘情况
// 1
const firstNode = nodes[0]
if ($isTextNode(firstNode)) {
const parentNode = firstNode.getParent()
if ($isMarkNode(parentNode)) {
nodes.unshift(parentNode)
}
for (let i = 0; i < nodes.length; i++) {
if (nodes[i] === parentNode) {
nodes.splice(i, 1)
break
}
}
}
// const firstNode = nodes[0]
// if ($isTextNode(firstNode)) {
// const parentNode = firstNode.getParent()
// if ($isMarkNode(parentNode)) {
// nodes.unshift(parentNode)
// }
// for (let i = 0; i < nodes.length; i++) {
// if (nodes[i] === parentNode) {
// nodes.splice(i, 1)
// break
// }
// }
// }
// 2
const textNodes: TextNode[] = []
for (let i = 0; i < nodes.length; i++) {
Expand Down

0 comments on commit 79bb1d2

Please sign in to comment.