Skip to content

Commit 9908134

Browse files
committed
fix(editor): add "link to page" as first link action in Text menubar
Fixes: #2332 Requires nextcloud/text#8368 Signed-off-by: Jonas <jonas@freesources.org>
1 parent af908a0 commit 9908134

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

playwright/e2e/page-content.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,22 @@ test.describe('Page content', () => {
2525

2626
await runOcc(['app:disable', 'whiteboard'])
2727
})
28+
29+
test('link to page from link menu', async ({ user, page, collective, editor }) => {
30+
const sourcePage = await collective.createPage({ title: 'Source page', user, page })
31+
const targetPage = await collective.createPage({ title: 'Target page', user, page })
32+
await sourcePage.open(true)
33+
34+
editor.setMode(true)
35+
await editor.clickMenu('Insert link', 'Link to page')
36+
await editor.smartPickerSearch.pressSequentially('Target page')
37+
38+
await editor.smartPicker.locator('.search-result').filter({ hasText: 'Target page' }).click()
39+
40+
const pageWidget = editor.getContent().locator('.widget-custom a.collective-page')
41+
42+
await expect(pageWidget).toBeVisible()
43+
const origin = new URL(page.url()).origin
44+
await expect(pageWidget).toHaveAttribute('href', origin + targetPage.getPageUrl())
45+
})
2846
})

playwright/support/sections/EditorSection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ export class EditorSection {
1111
public isEdit: boolean
1212
public readonly editor: Locator
1313
public readonly reader: Locator
14+
public readonly smartPicker: Locator
15+
public readonly smartPickerSearch: Locator
1416

1517
constructor(public readonly page: Page) {
1618
this.isEdit = false
1719
this.editor = this.page.locator('[data-cy-collectives="editor"]')
1820
this.reader = this.page.locator('[data-cy-collectives="reader"]')
21+
this.smartPicker = this.page.getByRole('dialog')
22+
this.smartPickerSearch = this.smartPicker.getByPlaceholder('Search', { exact: true })
1923
}
2024

2125
public setMode(edit: boolean) {

src/composables/useEditor.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6+
import { t } from '@nextcloud/l10n'
67
import debounce from 'debounce'
7-
import { computed, markRaw, nextTick, onBeforeUnmount, ref, watch } from 'vue'
8+
import { computed, defineCustomElement, markRaw, nextTick, onBeforeUnmount, ref, watch } from 'vue'
9+
import { getLinkWithPicker } from '@nextcloud/vue/components/NcRichText'
10+
import PageIcon from '../components/Icon/PageIcon.vue'
811
import { useCollectivesStore } from '../stores/collectives.js'
912
import { usePagesStore } from '../stores/pages.js'
1013
import { useRootStore } from '../stores/root.js'
@@ -81,13 +84,35 @@ export function useEditor(davContent) {
8184
return
8285
}
8386

87+
// Define PageIcon as custom web component
88+
if (!window.customElements.get('page-icon')) {
89+
const PageIconCE = defineCustomElement({
90+
...PageIcon,
91+
props: {
92+
...PageIcon.props,
93+
size: {
94+
type: Number,
95+
default: 20,
96+
},
97+
},
98+
}, { shadowRoot: false })
99+
customElements.define('page-icon', PageIconCE)
100+
}
101+
84102
editorPromise = window.OCA.Text.createEditor({
85103
el: editorEl.value,
86104
fileId: page.id,
87105
filePath: `/${pagesStore.pageFilePath(page)}`,
88106
readOnly: false,
89107
shareToken: rootStore.shareTokenParam || null,
90108
autofocus: false,
109+
menubarLinkCustomAction: {
110+
label: t('collectives', 'Link to page'),
111+
icon: 'page-icon',
112+
action: () => {
113+
return getLinkWithPicker('collectives-ref-pages', false)
114+
},
115+
},
91116
onCreate: ({ markdown }) => {
92117
updateEditorContentDebounced(markdown)
93118
},

0 commit comments

Comments
 (0)