Skip to content

Commit

Permalink
fix(annotation): active render in delete cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed Mar 28, 2023
1 parent 2088177 commit aecc7a2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/better-write-plugin-annotations/src/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export const PluginAnnotationsSet = (

stores.PROJECT.annotations.folders =
stores.PROJECT.annotations.folders.filter((f) => f.id !== folder.id)

setActive()
}

const createFile = (
Expand All @@ -97,6 +99,18 @@ export const PluginAnnotationsSet = (
return file
}

const setActive = () => {
if (stores.PROJECT.type === 'only-annotations') {
const folder = stores.PROJECT.annotations.folders.find((f) =>
f.files.find((f) => f)
)

if (!folder || folder.files.length === 0)
createFile(stores.PROJECT.annotations.folders[0])
else start(folder.files[0])
}
}

const deleteFile = (
folder: ProjectStateAnnotationFolder,
file: ProjectStateAnnotationFile
Expand All @@ -111,6 +125,8 @@ export const PluginAnnotationsSet = (
stores.PROJECT.annotations.folders[targetId].files.filter(
(f) => f.id !== file.id
)

setActive()
}

const start = async (file: ProjectStateAnnotationFile) => {
Expand All @@ -120,7 +136,7 @@ export const PluginAnnotationsSet = (

await nextTick

await Editor.make()
Editor.make()
.config((ctx) => {
ctx.set(rootCtx, document.querySelector('#bw-wysiwyg'))

Expand Down

0 comments on commit aecc7a2

Please sign in to comment.