Skip to content

Commit

Permalink
perf: some details
Browse files Browse the repository at this point in the history
  • Loading branch information
1943time committed Dec 22, 2023
1 parent d4cb6a7 commit 82b3812
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bluestone",
"version": "0.12.3",
"version": "0.12.4",
"description": "",
"main": "./out/main/index.js",
"license": "AGPL-3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/components/Set.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ export const Set = observer(() => {
<div className={'text-sm'}>
<span className={'mr-1'}>{configStore.zh ? '显示浮动栏' : 'Show floating bar'}</span>
<Help text={
configStore.zh ? '选中文字不再显示浮动栏,仍然可以可以使用Format菜单中的快捷键操作文字格式,或使用Markdown语法转换' :
'Selecting text will no longer display a floating bar, and you can still use the shortcut keys in the Format menu to manipulate text formatting or use Markdown syntax conversion'
configStore.zh ? '选中文字不再显示浮动栏,仍然可以可以使用"格式"菜单中的快捷键操作文字格式,或使用Markdown语法转换' :
'Selecting text will no longer display a floating bar, and you can still use the shortcut keys in the "Format" menu to manipulate text formatting or use Markdown syntax conversion'
}/>
</div>
<div>
Expand Down
62 changes: 35 additions & 27 deletions src/renderer/src/editor/RenamePasteFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {message$} from '../utils'
import {configStore} from '../store/config'
import {ReactEditor} from 'slate-react'
import {Input, Modal} from 'antd'
import React, {useEffect} from 'react'
import React, {useCallback, useEffect} from 'react'
import {EditorStore} from './store'
import {useLocalState} from '../hooks/useLocalState'
import isHotkey from 'is-hotkey'

export const RenamePasteFile = observer(({open, file, onClose, store}: {
open: boolean
Expand All @@ -33,42 +34,49 @@ export const RenamePasteFile = observer(({open, file, onClose, store}: {
})
}
}, [open])

const save = useCallback(async () => {
if (/^[\w\u4e00-\u9fa5]+$/.test(state.saveFileName)) {
const name = state.saveFileName + state.ext
const path = await MainApi.getCachePath()
const targetPath = treeStore.root ? join(treeStore.root!.filePath, '.images', name) : join(path, 'images', name)
if (existsSync(targetPath)) {
return message$.next({
type: 'warning',
content: configStore.zh ? '文件名已存在' : 'The file name already exists'
})
}
const mediaPath = await store.saveFile({
name,
buffer: await file.arrayBuffer()
})
onClose()
ReactEditor.focus(store.editor)
store.insertInlineNode(mediaPath)
} else {
message$.next({
type: 'warning',
content: configStore.zh ? '请输入正确文件名称' : 'Please enter the correct file name'
})
return Promise.reject()
}
}, [file, store])
return (
<Modal
width={400}
onCancel={onClose}
open={open}
onOk={async () => {
if (/^[\w\u4e00-\u9fa5]+$/.test(state.saveFileName)) {
const name = state.saveFileName + state.ext
const path = await MainApi.getCachePath()
const targetPath = treeStore.root ? join(treeStore.root!.filePath, '.images', name) : join(path, 'images', name)
if (existsSync(targetPath)) {
return message$.next({
type: 'warning',
content: configStore.zh ? '文件名已存在' : 'The file name already exists'
})
}
const mediaPath = await store.saveFile({
name,
buffer: await file.arrayBuffer()
})
onClose()
ReactEditor.focus(store.editor)
store.insertInlineNode(mediaPath)
} else {
message$.next({
type: 'warning',
content: configStore.zh ? '请输入正确文件名称' : 'Please enter the correct file name'
})
return Promise.reject()
}
}}
onOk={save}
title={configStore.zh ? '插入图片' : 'Insert Image'}
>
<Input
autoFocus={true}
className={'rename-input'}
onKeyDown={e => {
if (isHotkey('enter', e)) {
save()
}
}}
placeholder={configStore.zh ? '请输入文件名' : 'Please enter file name'} addonAfter={state.ext}
value={state.saveFileName}
onChange={e => setState({saveFileName: e.target.value})}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/editor/tools/MediaAttr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const MediaAttr = observer(() => {
if (!nodeRef.current?.[0].url) {
setTimeout(() => {
domRef.current?.querySelector('input')?.select()
})
}, 30)
}
}
}, [])
Expand Down

0 comments on commit 82b3812

Please sign in to comment.