From c902f6b76b9747cc4c7de851fdcfa9e79b95414a Mon Sep 17 00:00:00 2001 From: Ran Luo Date: Tue, 3 Jul 2018 10:49:46 +0800 Subject: [PATCH] bugfix: #406 relative image path not display (#411) --- src/editor/utils/index.js | 4 ++-- src/renderer/store/editor.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/editor/utils/index.js b/src/editor/utils/index.js index ee6a023b..a79a4317 100644 --- a/src/editor/utils/index.js +++ b/src/editor/utils/index.js @@ -180,7 +180,7 @@ export const getImageInfo = src => { const imageExtension = EXT_REG.test(src) const isUrl = URL_REG.test(src) if (imageExtension) { - if (isUrl || !window.__dirname) { + if (isUrl || !window.DIRNAME) { return { isUnknownType: false, src @@ -188,7 +188,7 @@ export const getImageInfo = src => { } else { return { isUnknownType: false, - src: 'file://' + path.resolve(window.__dirname, src) + src: 'file://' + path.resolve(window.DIRNAME, src) } } } else if (isUrl && !imageExtension) { diff --git a/src/renderer/store/editor.js b/src/renderer/store/editor.js index 2f39c255..0830d9cb 100644 --- a/src/renderer/store/editor.js +++ b/src/renderer/store/editor.js @@ -6,7 +6,6 @@ import { getOptionsFromState, getSingleFileState, getBlankFileState } from './he import notice from '../services/notification' const toc = require('markdown-toc') - const state = { lineEnding: 'lf', currentFile: {}, @@ -28,7 +27,8 @@ const mutations = { SET_CURRENT_FILE (state, currentFile) { const oldCurrentFile = state.currentFile if (!oldCurrentFile.id || oldCurrentFile.id !== currentFile.id) { - const { markdown, cursor, history } = currentFile + const { markdown, cursor, history, pathname } = currentFile + window.DIRNAME = pathname ? path.dirname(pathname) : '' // set state first, then emit file changed event state.currentFile = currentFile bus.$emit('file-changed', { markdown, cursor, renderCursor: true, history }) @@ -53,8 +53,8 @@ const mutations = { }, SET_PATHNAME (state, file) { const { filename, pathname, id } = file - if (id === state.currentFile.id) { - window.__dirname = path.dirname(pathname) + if (id === state.currentFile.id && pathname) { + window.DIRNAME = path.dirname(pathname) } const targetFile = state.tabs.filter(f => f.id === id)[0]