Skip to content

Commit

Permalink
fix: Preserve anchors in links that rendered as widget
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Miakshyn <[email protected]>
Signed-off-by: Jonas <[email protected]>
  • Loading branch information
Koc authored and mejo- committed Nov 5, 2024
1 parent 9729f64 commit 8745754
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/Reference/SearchablePageReferenceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Collective.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},
},
Expand Down
6 changes: 6 additions & 0 deletions src/components/Page/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 0 additions & 5 deletions src/mixins/editorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8745754

Please sign in to comment.