Skip to content

Commit

Permalink
fix(editor): sabe in unmounted editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Mar 20, 2022
1 parent b074948 commit c491fe1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/better-write-app/src/use/editor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useContextStore } from '@/store/context'
import { useEditorStore } from '@/store/editor'
import { useProjectStore } from '@/store/project'
import { useEntity } from '@/use/entity'
import { useEnv } from '@/use/env'
Expand All @@ -8,23 +7,19 @@ import { useLocalStorage } from '@/use/storage/local'
import { useFullscreen } from '@vueuse/core'
import { useHead } from '@vueuse/head'
import { usePlugin } from 'better-write-plugin-core'
import { computed, onMounted, watch } from 'vue'
import { computed, onBeforeUnmount, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { onBeforeRouteLeave, useRouter } from 'vue-router'
import { onBeforeRouteLeave } from 'vue-router'
import { useListener } from './listener'
import { useStorage } from './storage/storage'

export const useEditor = () => {
const PROJECT = useProjectStore()
const CONTEXT = useContextStore()
const EDITOR = useEditorStore()

const env = useEnv()
const project = useProject()
const storage = useStorage()
const entity = useEntity()
const local = useLocalStorage()
const router = useRouter()
const plugin = usePlugin()
const listener = useListener()
const { t } = useI18n()
Expand All @@ -39,6 +34,10 @@ export const useEditor = () => {
await local.onSaveProject()
})

onBeforeUnmount(async () => {
await local.onSaveProject()
})

listener.keyboard().add()

plugin.emit('plugin-theme-set')
Expand Down

0 comments on commit c491fe1

Please sign in to comment.