diff --git a/src/components/CollaborativeEditor.vue b/src/components/CollaborativeEditor.vue index 5ea0d33ffdf..7937d5cdff5 100644 --- a/src/components/CollaborativeEditor.vue +++ b/src/components/CollaborativeEditor.vue @@ -131,6 +131,7 @@ import createSyncServiceProvider from './../services/SyncServiceProvider.js' import { ATTACHMENT_RESOLVER, EDITOR_UPLOAD, + HOOK_FILE_WRITTEN, HOOK_MENTION_SEARCH, IS_MOBILE, } from './Editor.provider.ts' @@ -171,6 +172,7 @@ export default defineComponent({ inject: { isEmbedded: { default: false }, + fileWritten: { from: HOOK_FILE_WRITTEN, default: null }, }, props: { @@ -772,6 +774,7 @@ export default defineComponent({ // Cheap file update for Files app while the editor is still open this.fileNode.mtime = new Date() this.fileNode.size = new Blob([this.serialize()]).size + this.fileWritten?.(this.fileNode) emit('files:node:updated', this.fileNode) } this.$nextTick(() => { diff --git a/src/components/Editor.provider.ts b/src/components/Editor.provider.ts index 84ed5e56580..58f24ef802f 100644 --- a/src/components/Editor.provider.ts +++ b/src/components/Editor.provider.ts @@ -12,6 +12,7 @@ export const EDITOR_UPLOAD = Symbol('editor:upload') export const HOOK_MENTION_SEARCH = Symbol('hook:mention-search') export const HOOK_MENTION_INSERT = Symbol('hook:mention-insert') export const HOOK_MENUBAR_LINK_CUSTOM_ACTION = Symbol('menubar:link-custom-action') +export const HOOK_FILE_WRITTEN = Symbol('hook:file-written') export const useIsMobileMixin = { inject: { diff --git a/src/views/TextViewerWrapper.vue b/src/views/TextViewerWrapper.vue index af4a19638e5..04f7daf7cd7 100644 --- a/src/views/TextViewerWrapper.vue +++ b/src/views/TextViewerWrapper.vue @@ -7,9 +7,10 @@ import type { IFile } from '@nextcloud/files' import type { ViewerBeforeDownloadDetail } from '@nextcloud/viewer' -import { computed, onMounted, useHost, useTemplateRef } from 'vue' +import { computed, onMounted, provide, useHost, useTemplateRef } from 'vue' import ViewerComponent from '../components/ViewerComponent.vue' import ViewerVersionComparison from '../components/ViewerVersionComparison.vue' +import { HOOK_FILE_WRITTEN } from '../components/Editor.provider.ts' import { openMimetypesMarkdown } from '../helpers/mime.js' // Of what the viewer gives a handler's element (`ViewerProps` in @@ -24,6 +25,7 @@ const props = defineProps<{ const emit = defineEmits<{ loaded: [] 'update:canSwipe': [canSwipe: boolean] + 'update:file': [file: IFile] // 'update:comparison': [comparison: 'side-by-side' | 'differences'] }>() @@ -58,6 +60,10 @@ function showChange() { // emit('update:comparison', 'side-by-side') } +// The viewer keeps the editor for a file the editor wrote itself, rather +// than mounting a new one for what it takes as another version +provide(HOOK_FILE_WRITTEN, (file: IFile) => emit('update:file', file)) + // Swiping to select text would otherwise step to the next file onMounted(() => emit('update:canSwipe', false))