Skip to content

Commit

Permalink
fix: img load fail in multiple tab
Browse files Browse the repository at this point in the history
  • Loading branch information
1943time committed Oct 28, 2023
1 parent cff7a43 commit 7042b04
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/renderer/src/editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useEffect, useMemo, useRef} from 'react'
import React, {useCallback, useEffect, useLayoutEffect, useMemo, useRef} from 'react'
import {Editable, Slate} from 'slate-react'
import {Editor} from 'slate'
import {MElement, MLeaf} from './elements'
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/src/editor/EditorFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {MEditor} from './Editor'
import {Heading} from './tools/Leading'
import {Empty} from '../components/Empty'
import {Tab} from '../index'
import React, {useCallback, useEffect, useMemo} from 'react'
import React, {useCallback, useEffect, useLayoutEffect, useMemo} from 'react'
import {EditorStoreContext} from './store'
import {FloatBar} from './tools/FloatBar'
import {TableAttr} from './tools/TableAttr'
Expand Down Expand Up @@ -54,6 +54,11 @@ export const EditorFrame = observer(({tab}: {
window.electron.ipcRenderer.removeListener('open-search', open)
}
}, [])

useLayoutEffect(() => {
tab.store.openFilePath = tab.current?.filePath || null
}, [tab.current])

const mt = useMemo(() => mediaType(tab.current?.filePath || ''), [tab.current])
const size = useMemo(() => {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/editor/elements/media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function Media({element, attributes, children}: ElementProps<MediaNode>)
return
}
let realUrl = element.url
if (!element.url.startsWith('http') && !element.url.startsWith('file:') && treeStore.openedNote) {
const file = isAbsolute(element.url) ? element.url : join(treeStore.currentTab.current!.filePath, '..', element.url)
if (!element.url.startsWith('http') && !element.url.startsWith('file:')) {
const file = isAbsolute(element.url) ? element.url : join(store.openFilePath || '', '..', element.url)
const data = getImageData(file)
if (data) {
realUrl = data
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/src/editor/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class EditorStore {
container: null | HTMLDivElement = null
history = false
inputComposition = false
openFilePath: string | null = null
saveDoc$ = new Subject<any[] | null>()
get doc() {
return this.container?.querySelector('.content') as HTMLDivElement
Expand All @@ -67,6 +68,7 @@ export class EditorStore {
editor: false,
tableCellNode: false,
inputComposition: false,
openFilePath: false,
container: false,
highlightCache: false,
dragEl: false
Expand Down

0 comments on commit 7042b04

Please sign in to comment.