@@ -19,13 +19,15 @@ import { appDataDir } from '@tauri-apps/api/path'
1919import { v4 as uuid } from 'uuid'
2020import { convertImage } from '@/lib/utils'
2121import CustomFooter from './custom-footer'
22+ import { useLocalStorage } from 'react-use'
2223
2324export function MdEditor ( ) {
2425 const [ editor , setEditor ] = useState < Vditor > ( ) ;
2526 const { currentArticle, saveCurrentArticle, loading, activeFilePath } = useArticleStore ( )
2627 const { theme, setTheme } = useTheme ( )
2728 const t = useTranslations ( 'article.editor' )
2829 const { currentLocale } = useI18n ( )
30+ const [ localMode , setLocalMode ] = useLocalStorage < 'ir' | 'sv' | 'wysiwyg' > ( 'useLocalMode' , 'ir' )
2931
3032 function getLang ( ) {
3133 switch ( currentLocale ) {
@@ -100,7 +102,7 @@ export function MdEditor() {
100102 { name : 'link' , tipPosition : 's' } ,
101103 { name : 'table' , tipPosition : 's' } ,
102104 '|' ,
103- { name : 'edit-mode' , tipPosition : 's' , className : 'bottom' } ,
105+ { name : 'edit-mode' , tipPosition : 's' , className : 'bottom edit-mode-button ' } ,
104106 { name : 'preview' , tipPosition : 's' } ,
105107 { name : 'outline' , tipPosition : 's' } ,
106108 ]
@@ -132,14 +134,25 @@ export function MdEditor() {
132134 } ,
133135 after : ( ) => {
134136 setEditor ( vditor ) ;
137+ // 切换记录编辑模式
138+ const editModeButtons = vditor . vditor . element . querySelectorAll ( '.edit-mode-button .vditor-hint button' )
139+ editModeButtons . forEach ( button => {
140+ button . addEventListener ( 'click' , ( ) => {
141+ const mode = button . getAttribute ( 'data-mode' )
142+ if ( ! mode ) return
143+ setLocalMode ( mode as 'ir' | 'sv' | 'wysiwyg' )
144+ } )
145+ } )
135146 if ( activeFilePath === '' ) {
136147 vditor . setValue ( '' , true )
137148 }
149+
138150 } ,
139151 input : ( value ) => {
140152 saveCurrentArticle ( value )
141153 emitter . emit ( 'editor-input' )
142154 } ,
155+ mode : localMode ,
143156 upload : {
144157 async handler ( files : File [ ] ) {
145158 const store = await Store . load ( 'store.json' ) ;
0 commit comments