Skip to content

Commit 896b9f5

Browse files
authored
Merge pull request #5025 from nextcloud/backport/5021/stable28
2 parents 4f05508 + 42d0763 commit 896b9f5

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

src/helpers/files.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,17 @@ export const FilesWorkspaceHeader = new Header({
212212
},
213213

214214
render(el, folder, view) {
215+
if (vm) {
216+
// Enforce destroying of the old rendering and rerender as the FilesListHeader calls render on every folder change
217+
vm.$destroy()
218+
vm = null
219+
}
215220
const hasRichWorkspace = !!folder.attributes['rich-workspace-file'] || !!newWorkspaceCreated
216221
const path = newWorkspaceCreated ? dirname(newWorkspaceCreated.path) : folder.path
217222
const content = newWorkspaceCreated ? '' : folder.attributes['rich-workspace']
218223

224+
newWorkspaceCreated = false
225+
219226
import('vue').then((module) => {
220227
el.id = 'files-workspace-wrapper'
221228

@@ -239,6 +246,11 @@ export const FilesWorkspaceHeader = new Header({
239246

240247
updated(folder, view) {
241248
newWorkspaceCreated = false
249+
250+
// Currently there is not much use in updating the vue instance props since render is called on every folder change
251+
// removing the rendered element from the DOM
252+
// This is only relevant if switching to a folder that has no content as then the render function is not called
253+
242254
const hasRichWorkspace = !!folder.attributes['rich-workspace-file']
243255
vm.path = folder.path
244256
vm.hasRichWorkspace = hasRichWorkspace

src/views/RichWorkspace.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
-->
2222

2323
<template>
24-
<div v-if="enabled && file !== null"
24+
<div v-if="enabled && localHasRichWorkspace"
2525
id="rich-workspace"
2626
:class="{'focus': focus, 'dark': darkTheme }">
2727
<RichTextReader v-if="!loaded || !ready" :content="content" class="rich-workspace--preview" />
@@ -80,6 +80,8 @@ export default {
8080
},
8181
data() {
8282
return {
83+
// Keep track of a local copy of the hasRichWorkspace state as it might change after intitial rendering (e.g. when adding/removing the readme)
84+
localHasRichWorkspace: false,
8385
focus: false,
8486
folder: null,
8587
file: null,
@@ -105,8 +107,12 @@ export default {
105107
document.querySelector('#rich-workspace .text-editor__main').scrollTo(0, 0)
106108
}
107109
},
110+
hasRichWorkspace(value) {
111+
this.localHasRichWorkspace = value
112+
},
108113
},
109114
mounted() {
115+
this.localHasRichWorkspace = this.hasRichWorkspace
110116
if (this.enabled && this.hasRichWorkspace) {
111117
this.getFileInfo()
112118
}
@@ -137,6 +143,7 @@ export default {
137143
this.unlistenKeydownEvents()
138144
},
139145
reset() {
146+
this.localHasRichWorkspace = false
140147
this.file = null
141148
this.focus = false
142149
this.$nextTick(() => {
@@ -164,6 +171,7 @@ export default {
164171
this.editing = true
165172
this.loaded = true
166173
this.autofocus = autofocus || false
174+
this.localHasRichWorkspace = true
167175
return true
168176
})
169177
.catch((error) => {
@@ -212,19 +220,20 @@ export default {
212220
},
213221
onFileCreated(node) {
214222
if (SUPPORTED_STATIC_FILENAMES.includes(node.basename)) {
215-
this.showRichWorkspace()
223+
this.localHasRichWorkspace = true
224+
this.getFileInfo(true)
216225
}
217226
},
218227
onFileDeleted(node) {
219228
if (node.path === this.file.path) {
220-
this.hideRichWorkspace()
229+
this.localHasRichWorkspace = false
221230
}
222231
},
223232
onFileRenamed(node) {
224233
if (SUPPORTED_STATIC_FILENAMES.includes(node.basename)) {
225-
this.showRichWorkspace()
234+
this.localHasRichWorkspace = true
226235
} else if (node.fileid === this.file?.id && node.path !== this.file?.path) {
227-
this.hideRichWorkspace()
236+
this.localHasRichWorkspace = false
228237
}
229238
},
230239
},
@@ -241,11 +250,14 @@ export default {
241250
transition: max-height 0.5s cubic-bezier(0, 1, 0, 1);
242251
z-index: 61;
243252
position: relative;
244-
min-height: 30vh;
245253
}
246254
247255
.rich-workspace--preview {
248256
margin-top: 44px;
257+
258+
&:deep(div[contenteditable='false']) {
259+
margin: 0;
260+
}
249261
}
250262
251263
/* For subfolders, where there are no Recommendations */

0 commit comments

Comments
 (0)