Skip to content

Commit

Permalink
refactor: new file code
Browse files Browse the repository at this point in the history
  • Loading branch information
1943time committed Jan 6, 2024
1 parent 800b8a0 commit 86ab44a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
8 changes: 0 additions & 8 deletions src/renderer/src/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const MEditor = observer(({note}: {
})
const saveFile = useRef<File>()
const store = useEditorStore()
const inCode = useRef(false)
const changedMark = useRef(false)
const editor = store.editor
const value = useRef<any[]>([EditorUtils.p])
Expand Down Expand Up @@ -212,13 +211,6 @@ export const MEditor = observer(({note}: {
window.electron.ipcRenderer.removeListener('save-doc', save)
}
}, [])
useEffect(() => {
const [node] = Editor.nodes(store.editor, {
match: n => n.type === 'code',
mode: 'highest'
})
inCode.current = !!node
}, [store.sel])

const drop = useCallback((e: React.DragEvent<HTMLDivElement>) => {
const dragNode = treeStore.dragNode
Expand Down
10 changes: 4 additions & 6 deletions src/renderer/src/store/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {basename, join, parse, sep} from 'path'
import {appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, statSync} from 'fs'
import {MainApi} from '../api/main'
import {MenuKey} from '../utils/keyboard'
import {message$, modal$, stat} from '../utils'
import {message$, stat} from '../utils'
import {Watcher} from './watch'
import {Subject} from 'rxjs'
import {mediaType} from '../editor/utils/dom'
Expand All @@ -16,9 +16,8 @@ import {refactor, renameAllFiles} from './refactor'
import {EditorStore} from '../editor/store'
import {parserMdToSchema} from '../editor/parser/parser'
import {shareStore} from '../server/store'
import {BaseSelection} from 'slate'
import {mix} from 'framer-motion'
import isHotkey from 'is-hotkey'
import {EditorUtils} from '../editor/utils/editorUtils'

export class TreeStore {
treeTab: 'folder' | 'search' = 'folder'
Expand Down Expand Up @@ -269,7 +268,7 @@ export class TreeStore {
if (file?.ext !== 'md' && file?.ext !== 'markdown') return
if (file.schema) return file
const [schema] = await parserMdToSchema([readFileSync(file.filePath, {encoding: 'utf-8'})])
file.schema = schema
file.schema = schema?.length ? schema : [EditorUtils.p]
return file
}

Expand All @@ -294,7 +293,6 @@ export class TreeStore {

openNote(file: string | IFileItem, scroll = true) {
const filePath = typeof file === 'string' ? file : file.filePath
document.title = this.root ? `${basename(this.root.filePath)}-${basename(filePath)}` : basename(filePath)
if (this.currentTab.current?.filePath === filePath) return
this.checkOtherTabsShouldUpdate()
if (this.root && filePath.startsWith(this.root.filePath)) {
Expand Down Expand Up @@ -461,7 +459,7 @@ export class TreeStore {
} else {
if (file.mode === 'copy') {
appendFileSync(path, readFileSync(file.copyItem!.filePath, {encoding: 'utf-8'}), {encoding: 'utf-8'})
file.schema = file.copyItem?.schema || []
file.schema = file.copyItem?.schema || [EditorUtils.p]
} else {
appendFileSync(path, '', {encoding: 'utf-8'})
}
Expand Down

0 comments on commit 86ab44a

Please sign in to comment.