diff --git a/main.js b/main.js
index 44e9820..7bd9a9a 100644
--- a/main.js
+++ b/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)))
}
diff --git a/package-lock.json b/package-lock.json
index 72d484a..f391663 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -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",
diff --git a/package.json b/package.json
index 81a9079..99adaf1 100644
--- a/package.json
+++ b/package.json
@@ -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": {
diff --git a/src/components/ItemTree/index.jsx b/src/components/ItemTree/index.jsx
index 17c5089..7c97dd4 100644
--- a/src/components/ItemTree/index.jsx
+++ b/src/components/ItemTree/index.jsx
@@ -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": ,
+ "icon": dirFlag?:fileName.endsWith(".md")?:,
"dirFlag": dirFlag,
"children": []
});
diff --git a/src/pages/Note/Hlexical/index.jsx b/src/pages/Note/Hlexical/index.jsx
index f8c9ff1..9db27f5 100644
--- a/src/pages/Note/Hlexical/index.jsx
+++ b/src/pages/Note/Hlexical/index.jsx
@@ -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
Enter some rich text...
;
}
@@ -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 (
@@ -95,7 +117,8 @@ export default function Hlexical() {
{/*
*/}
-
+
+ {/**/}
diff --git a/src/pages/Note/index.jsx b/src/pages/Note/index.jsx
index 2cecd39..a9b504a 100644
--- a/src/pages/Note/index.jsx
+++ b/src/pages/Note/index.jsx
@@ -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:
,
+ children:
,
key: openFile.filePath,
}
])
diff --git a/src/utils/File/index.jsx b/src/utils/File/index.jsx
index ae4375d..9fc53ec 100644
--- a/src/utils/File/index.jsx
+++ b/src/utils/File/index.jsx
@@ -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,)
}
\ No newline at end of file