浏览代码

1. 图片的目录与fileName不一致
2. 在mac里,无法修改图片的名称

liuyang 7 年之前
父节点
当前提交
7541a85dfa
共有 3 个文件被更改,包括 22 次插入2 次删除
  1. 4 0
      app/moe-action.js
  2. 1 0
      package.json
  3. 17 2
      views/main/moe-document.js

+ 4 - 0
app/moe-action.js

@@ -95,6 +95,8 @@ class MoeditorAction {
                             hexoWindow.hexoeditorWindow.window.setRepresentedFilename(hexoWindow.hexoeditorWindow.fileName);
                             hexoWindow.hexoeditorWindow.window.webContents.send('refresh-editor', {});
                             app.addRecentDocument(fileName);
+                            // TODO-ly 解决第一次图片保存地址不对的问题
+                            hexoWindow.hexoeditorWindow.window.webContents.send('open-newfile', {});
                         }
                         notOpened = false;
                     }
@@ -141,6 +143,8 @@ class MoeditorAction {
                             hexoWindow.hexoeditorWindow.window.setRepresentedFilename(hexoWindow.hexoeditorWindow.fileName);
                             hexoWindow.hexoeditorWindow.window.webContents.send('refresh-editor', {});
                             app.addRecentDocument(filename);
+                            // TODO-ly 解决第一次图片保存地址不对的问题
+                            hexoWindow.hexoeditorWindow.window.webContents.send('open-newfile', {});
                             hexoWindow.focus();
                             break;
                         } catch (e) {

+ 1 - 0
package.json

@@ -69,6 +69,7 @@
     "codemirror": "^5.18.2",
     "configstore": "^2.1.0",
     "cos-nodejs-sdk-v5": "^2.2.6",
+    "electron-platform": "^1.2.0",
     "electron-localshortcut": "^0.6.1",
     "electron-titlebar": "0.0.2",
     "flowchart.js": "^1.6.3",

+ 17 - 2
views/main/moe-document.js

@@ -29,6 +29,8 @@ window.path = require('path');
 window.url = require('url');
 global.log4js = window.log4js = moeApp.getLog4js();
 global.log = window.log = log4js.getLogger('Front');
+// TODO-ly 引入平台判断库
+const platform = require('electron-platform');
 
 $(() => {
     const dialog = require('electron').remote.dialog;
@@ -166,6 +168,13 @@ $(() => {
     require('electron').ipcRenderer.on('set-title', (e, fileName) => {
         document.getElementsByTagName('title')[0].innerText = 'HexoEditor - ' + path.basename(fileName);
     });
+    // TODO-ly 解决第一次图片保存地址不对的问题
+    require('electron').ipcRenderer.on('open-newfile', () => {
+        let fileName = path.basename(hexoWindow.fileName, path.extname(hexoWindow.fileName));
+        if(fileName !== imgManager.postName){
+            imgManager.renameDirPath(fileName);
+        }
+    });
 
     //加载填图功能
     const ImgManager = require('./hexo-image');
@@ -280,6 +289,9 @@ $(() => {
                             imgManager.renameDirPath(nameNew);
                         })
                     })
+                } else {
+                    // TODO-ly 解决图片路径不对的问题
+                    imgManager.renameDirPath(nameNew);
                 }
             }
             if (force) {
@@ -377,9 +389,12 @@ $(() => {
         }
     }, true);
     document.getElementById("editor").addEventListener("click", e => {
-        if (e.ctrlKey) {
+        // TODO-ly 判断按下的按键
+        let key = platform.isDarwin ? e.metaKey : e.ctrlKey;
+        if (key) {
             $('span.cm-string.cm-url').unbind('click').click(e => {
-                if (e.ctrlKey) {
+                key = platform.isDarwin ? e.metaKey : e.ctrlKey;
+                if (key) {
                     e.stopPropagation();
                     // e.defaultPrevented();
                     const innerLink = e.target.innerText.replace(/^\((.*)\)$/, '$1');