From 6b37631f81262f2b182e6b260735c772038473a6 Mon Sep 17 00:00:00 2001 From: Kostiantyn Miakshyn Date: Mon, 4 Nov 2024 01:05:53 +0100 Subject: [PATCH] fix: Preserve anchors in links that rendered as widget Signed-off-by: Kostiantyn Miakshyn Signed-off-by: Jonas --- lib/Reference/SearchablePageReferenceProvider.php | 3 +++ src/components/Collective.vue | 2 +- src/components/Page/TextEditor.vue | 6 ++++++ src/mixins/editorMixin.js | 5 ----- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Reference/SearchablePageReferenceProvider.php b/lib/Reference/SearchablePageReferenceProvider.php index d8a3750de..b46fc4cb2 100644 --- a/lib/Reference/SearchablePageReferenceProvider.php +++ b/lib/Reference/SearchablePageReferenceProvider.php @@ -205,6 +205,9 @@ private function resolve(string $referenceText, bool $public = false, string $sh $collectivesLink = $this->urlGenerator->linkToRouteAbsolute('collectives.start.index') . ($public ? 'p/' . $sharingToken . '/' : ''); $link = $collectivesLink . $this->pageService->getPageLink($collective->getName(), $page); + if (str_contains($referenceText, '#')) { + $link .= '#' . explode('#', $referenceText)[1]; + } $reference = new Reference($link); $pageEmoji = $page->getEmoji(); $refTitle = $pageEmoji ? $pageEmoji . ' ' . $page->getTitle() : $page->getTitle(); diff --git a/src/components/Collective.vue b/src/components/Collective.vue index f9739731c..0b0f0ab76 100644 --- a/src/components/Collective.vue +++ b/src/components/Collective.vue @@ -94,7 +94,7 @@ export default { }, 'notFound'(current) { if (current && this.currentFileIdPage) { - this.$router.replace(this.pagePath(this.currentFileIdPage)) + this.$router.replace(this.pagePath(this.currentFileIdPage) + document.location.hash) } }, }, diff --git a/src/components/Page/TextEditor.vue b/src/components/Page/TextEditor.vue index 8de2d6bb0..041aa6482 100644 --- a/src/components/Page/TextEditor.vue +++ b/src/components/Page/TextEditor.vue @@ -149,6 +149,12 @@ export default { this.setTextEdit() this.done('newPageContent') } + + if (document.location.hash) { + // scroll to the corresponding header if the page was loaded with a hash + const element = document.querySelector(`[href="${document.location.hash}"]`) + element?.click() + } }, async stopEdit() { diff --git a/src/mixins/editorMixin.js b/src/mixins/editorMixin.js index d7bdcaebb..20c66a9c7 100644 --- a/src/mixins/editorMixin.js +++ b/src/mixins/editorMixin.js @@ -128,11 +128,6 @@ export default { onLoaded: () => { // TODO: remove check once we only support Nextcloud 30+ this.reader.setSearchQuery && this.reader.setSearchQuery(this.searchQuery, this.matchAll) - if (document.location.hash) { - // scroll to the corresponding header if the page was loaded with a hash - const element = document.querySelector(`[href="${document.location.hash}"]`) - element?.click() - } }, onSearch: (results) => { this.setSearchResults(results)