feat:文件正常打开
This commit is contained in:
parent
00b381ba86
commit
b7ac57f6a8
11
main.js
11
main.js
|
@ -19,6 +19,17 @@ const createWindow = () => {
|
|||
win.loadURL('http://localhost:3000')
|
||||
// 打开开发工具
|
||||
win.webContents.openDevTools()
|
||||
win.webContents.on('before-input-event', (event, input) => {
|
||||
// if (input.control && input.key.toLowerCase() === 's') {
|
||||
// console.log('Pressed Control+s')
|
||||
// event.preventDefault()
|
||||
// }
|
||||
console.log('Pressed ',input.key)
|
||||
if (input.key==='f5'){
|
||||
console.log('Pressed f5')
|
||||
win.reload()
|
||||
}
|
||||
})
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate(menuRebuild(win)))
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"dependencies": {
|
||||
"electron-squirrel-startup": "^1.0.0",
|
||||
"electron-store": "^8.1.0",
|
||||
"mousetrap": "^1.6.5",
|
||||
"node-sass": "^7.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -18478,6 +18479,11 @@
|
|||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/mousetrap": {
|
||||
"version": "1.6.5",
|
||||
"resolved": "https://registry.npmmirror.com/mousetrap/-/mousetrap-1.6.5.tgz",
|
||||
"integrity": "sha512-QNo4kEepaIBwiT8CDhP98umTetp+JNfQYBWvC1pc6/OAibuXtRcxZ58Qz8skvEHYvURne/7R8T5VoOI7rDsEUA=="
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmmirror.com/ms/-/ms-2.1.2.tgz",
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
"dependencies": {
|
||||
"electron-squirrel-startup": "^1.0.0",
|
||||
"electron-store": "^8.1.0",
|
||||
"mousetrap": "^1.6.5",
|
||||
"node-sass": "^7.0.3"
|
||||
},
|
||||
"browser": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React, {useEffect, useMemo, useState} from 'react';
|
||||
import {Input, Tree} from 'antd';
|
||||
import {FolderOutlined, FileMarkdownOutlined} from '@ant-design/icons';
|
||||
import {FolderOutlined, FileMarkdownOutlined,FileOutlined} from '@ant-design/icons';
|
||||
import "./index.less"
|
||||
const {Search} = Input;
|
||||
import store from "../../redux/store";
|
||||
|
@ -43,10 +43,11 @@ function generateChildList(fileList) {
|
|||
const result = []
|
||||
for (let i = 0; i < fileList.length; i++) {
|
||||
const {fileName, filePath, dirFlag} = fileList[i];
|
||||
|
||||
result.push({
|
||||
"key": filePath,
|
||||
"title": fileName,
|
||||
"icon": <FolderOutlined/>,
|
||||
"icon": dirFlag?<FolderOutlined/>:fileName.endsWith(".md")?<FileMarkdownOutlined/>:<FileOutlined />,
|
||||
"dirFlag": dirFlag,
|
||||
"children": []
|
||||
});
|
||||
|
|
|
@ -26,6 +26,9 @@ import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|||
import {importFile} from "../../../utils/File"
|
||||
import {CLEAR_HISTORY_COMMAND} from "lexical";
|
||||
import ActionPlugin from "../../../components/ActionPlug"
|
||||
import {func} from "prop-types";
|
||||
|
||||
|
||||
function Placeholder() {
|
||||
return <div className="editor-placeholder">Enter some rich text...</div>;
|
||||
}
|
||||
|
@ -62,8 +65,28 @@ function OnChangePlugin({ onChange }) {
|
|||
});
|
||||
}, [editor, onChange]);
|
||||
}
|
||||
function ImportFilePlugin(props) {
|
||||
const [editor] = useLexicalComposerContext();
|
||||
useEffect(()=>{
|
||||
importFile(props.filePath).then(value=>{
|
||||
console.log('value.toString()',value.toString())
|
||||
const editorState = editor.parseEditorState(
|
||||
JSON.stringify(JSON.parse(value.toString()).editorState)
|
||||
);
|
||||
editor.setEditorState(editorState);
|
||||
editor.dispatchCommand(CLEAR_HISTORY_COMMAND, undefined);
|
||||
}).catch(error=>
|
||||
console.error(error)
|
||||
)
|
||||
},[])
|
||||
}
|
||||
|
||||
export default function Hlexical() {
|
||||
// 从字符串化 JSON 设置编辑器状态
|
||||
// const editorState = editor.parseEditorState(editorStateJSONString);
|
||||
// editor.setEditorState(editorState);
|
||||
|
||||
export default function Hlexical(props) {
|
||||
console.log("this.props.filePath:",props.filePath)
|
||||
const [editorState, setEditorState] = useState();
|
||||
function onChange(editorState) {
|
||||
// Call toJSON on the EditorState object, which produces a serialization safe string
|
||||
|
@ -72,7 +95,6 @@ export default function Hlexical() {
|
|||
// However, we still have a JavaScript object, so we need to convert it to an actual string with JSON.stringify
|
||||
setEditorState(JSON.stringify(editorStateJSON));
|
||||
}
|
||||
|
||||
return (
|
||||
<LexicalComposer initialConfig={editorConfig}>
|
||||
<div className="editor-container">
|
||||
|
@ -95,7 +117,8 @@ export default function Hlexical() {
|
|||
{/*<ListMaxIndentLevelPlugin maxDepth={7} />*/}
|
||||
<MarkdownShortcutPlugin transformers={TRANSFORMERS} />
|
||||
<OnChangePlugin onChange={onChange}/>
|
||||
<ActionPlugin/>
|
||||
<ImportFilePlugin filePath={props.filePath}/>
|
||||
{/*<ActionPlugin/>*/}
|
||||
</div>
|
||||
</div>
|
||||
</LexicalComposer>
|
||||
|
|
|
@ -12,6 +12,7 @@ import ItemTree from "../../components/ItemTree";
|
|||
import './index.less'
|
||||
import store from "../../redux/store";
|
||||
import {isEmpty} from "../../utils/ObjectUtils";
|
||||
|
||||
const {Header, Sider, Content} = Layout;
|
||||
const Note = () => {
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
|
@ -25,11 +26,14 @@ const Note = () => {
|
|||
store.subscribe(() => {
|
||||
const openFile = store.getState().clickFileMessage.data;
|
||||
console.log("store.getState().clickFileMessage.data:",openFile,items)
|
||||
if (!isEmpty(openFile)&&activeKey!==openFile.filePath){
|
||||
setActiveKey(openFile.filePath)
|
||||
}
|
||||
if (items.filter(fileItem => fileItem.key === openFile.filePath).length === 0&& !isEmpty(openFile)) {
|
||||
setItems([...items,
|
||||
{
|
||||
label: openFile.fileName,
|
||||
children: <div className="HlexicalName"><Hlexical/></div>,
|
||||
children: <div className="HlexicalName"><Hlexical filePath={openFile.filePath} /></div>,
|
||||
key: openFile.filePath,
|
||||
}
|
||||
])
|
||||
|
|
|
@ -4,5 +4,9 @@ import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
|
|||
const fs = window.require("fs").promises
|
||||
|
||||
export async function importFile(pathName) {
|
||||
return await fs.readFile(pathName)
|
||||
return await fs.readFile(pathName)
|
||||
}
|
||||
|
||||
export function overWriteFile(filePath) {
|
||||
fs.writeFile(filePath,)
|
||||
}
|
Loading…
Reference in New Issue