Skip to content

Commit 740cf53

Browse files
committed
feat: save all editorcomponents before downloading a file
Signed-off-by: silver <s.szmajduch@posteo.de>
1 parent 2f7800e commit 740cf53

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

src/views/Viewer.vue

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,14 @@
7676
@click="showSidebar">
7777
{{ t('viewer', 'Open sidebar') }}
7878
</NcActionButton>
79-
<NcActionLink v-if="canDownload"
80-
:download="currentFile.basename"
79+
<NcActionButton v-if="canDownload"
8180
:close-after-click="true"
82-
:href="downloadPath">
81+
@click="onDownload">
8382
<template #icon>
8483
<Download :size="20" />
8584
</template>
8685
{{ t('viewer', 'Download') }}
87-
</NcActionLink>
86+
</NcActionButton>
8887
<NcActionButton v-if="canDelete"
8988
:close-after-click="true"
9089
@click="onDelete">
@@ -1006,12 +1005,7 @@ export default defineComponent({
10061005
if (event.key === 's' && event.ctrlKey === true) {
10071006
event.preventDefault()
10081007
if (this.canDownload) {
1009-
const a = document.createElement('a')
1010-
a.href = this.currentFile.source ?? this.currentFile.davPath
1011-
a.download = this.currentFile.basename
1012-
document.body.appendChild(a)
1013-
a.click()
1014-
document.body.removeChild(a)
1008+
this.onDownload()
10151009
}
10161010
}
10171011
},
@@ -1196,6 +1190,49 @@ export default defineComponent({
11961190
this.toggleEditor(true)
11971191
},
11981192
1193+
/**
1194+
* Save active Text editors before downloading
1195+
*/
1196+
async onDownload() {
1197+
if (!this.canDownload) {
1198+
return
1199+
}
1200+
1201+
// Check if Text app is available and has active editor components
1202+
if (window.OCA?.Text?.editorComponents) {
1203+
try {
1204+
logger.debug('Text app detected, attempting to save before download')
1205+
1206+
const editorComponents = window.OCA.Text.editorComponents
1207+
1208+
// Text app uses a Set to store editor components
1209+
if (editorComponents instanceof Set) {
1210+
for (const component of editorComponents) {
1211+
if (component && typeof component.save === 'function') {
1212+
logger.debug('Calling save on Text editor component')
1213+
await component.save()
1214+
}
1215+
}
1216+
}
1217+
} catch (error) {
1218+
logger.warn('Failed to save Text editor before download', { error })
1219+
// Continue with download anyway
1220+
}
1221+
}
1222+
1223+
this.performDownload()
1224+
},
1225+
1226+
performDownload() {
1227+
logger.debug('Performing download', { file: this.currentFile })
1228+
const a = document.createElement('a')
1229+
a.href = this.currentFile.source ?? this.currentFile.davPath
1230+
a.download = this.currentFile.basename
1231+
document.body.appendChild(a)
1232+
a.click()
1233+
document.body.removeChild(a)
1234+
},
1235+
11991236
handleTrapElementsChange(element) {
12001237
this.trapElements.push(element)
12011238
},

0 commit comments

Comments
 (0)