From 308a7750aa620d2989356f5a040e1480af5258e4 Mon Sep 17 00:00:00 2001 From: Jonas Date: Wed, 4 Nov 2026 17:56:53 +0100 Subject: [PATCH] fix(viewer): keep the editor mounted after saving The viewer mounts a new element when the file it shows is announced with another etag, unless the element wrote the file and says so with update:file first. Text did not, and with files_lock every save announced the file with the etag taken under Text's lock. The viewer mounted the editor again, and each closing editor unlocked the file, changing its etag and announcing it once more, so the editor kept reloading. Tell the viewer of each save from the viewer's element, before announcing it to Files. Signed-off-by: Jonas Assisted-by: ClaudeCode:claude-opus-5-5 --- src/components/CollaborativeEditor.vue | 3 +++ src/components/Editor.provider.ts | 1 + src/views/TextViewerWrapper.vue | 8 +++++++- 3 files changed, 11 insertions(+), 1 deletion(-) 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))