Skip to content

Commit d1eb9b7

Browse files
authored
Merge pull request #8616 from nextcloud/fix/folder_description_scroll
fix(folderDescription): fix max height in unfocused mode
2 parents 658a741 + df3d8ce commit d1eb9b7

3 files changed

Lines changed: 53 additions & 6 deletions

File tree

playwright/e2e/folder-description/navigate.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,40 @@ test('Shows Readme.md', async ({ open, editor }) => {
1919
await expect(editor.getHeading({ name: 'Folder description' })).toBeVisible()
2020
})
2121

22+
test.describe('Scroll reset on blur', () => {
23+
test.use({
24+
fileContent:
25+
'# Title\n\n' + Array(30).fill('A paragraph of text.').join('\n\n'),
26+
})
27+
28+
test('Scrolls back to top when focus is lost', async ({
29+
open,
30+
page,
31+
editor,
32+
}) => {
33+
await open()
34+
await editor.el.click()
35+
const heading = editor.getHeading({ name: 'Title' })
36+
await expect(page.locator('#rich-workspace')).toHaveClass(/focus/)
37+
await expect(heading).toBeInViewport()
38+
39+
// Scroll down withhin the content wrapper
40+
await page
41+
.locator('#rich-workspace .editor__content-wrapper')
42+
.evaluate((el) => {
43+
el.scrollTop = 400
44+
})
45+
await expect(heading).not.toBeInViewport()
46+
47+
// Blur by clicking outside the workspace
48+
await page
49+
.getByRole('navigation', { name: 'Current directory path' })
50+
.click()
51+
await expect(page.locator('#rich-workspace')).not.toHaveClass(/focus/)
52+
await expect(heading).toBeInViewport()
53+
})
54+
})
55+
2256
test('Hides in a different folder', async ({ editor, open, page, user }) => {
2357
await createFolder({ name: 'Other folder', owner: user })
2458
await open()

src/components/Editor.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,8 @@ export default defineComponent({
758758
this.emit('focus')
759759
},
760760
761-
onBlur() {
762-
this.emit('blur')
761+
onBlur({ event }) {
762+
this.emit('blur', event)
763763
},
764764
765765
onKeyboardSave() {

src/views/RichWorkspace.vue

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
active
2626
rich-workspace
2727
@ready="ready = true"
28-
@focus="onFocus" />
28+
@focus="onFocus"
29+
@blur="onBlur" />
2930
</div>
3031
</template>
3132

@@ -112,8 +113,8 @@ export default {
112113
focus(newValue) {
113114
if (!newValue) {
114115
document
115-
.querySelector('#rich-workspace .text-editor__main')
116-
.scrollTo(0, 0)
116+
.querySelector('#rich-workspace .editor__content-wrapper')
117+
?.scrollTo(0, 0)
117118
}
118119
},
119120
shouldRender(value) {
@@ -150,6 +151,14 @@ export default {
150151
this.hideMenu = false
151152
this.unlistenKeydownEvents()
152153
},
154+
onBlur(event) {
155+
// If focus moved to something inside the workspace (e.g. menubar), don't collapse
156+
if (this.$el.contains(event?.relatedTarget)) {
157+
return
158+
}
159+
this.focus = false
160+
this.hideMenu = true
161+
},
153162
reset() {
154163
this.file = null
155164
this.focus = false
@@ -294,11 +303,15 @@ export default {
294303
295304
#rich-workspace:deep(.editor__content-wrapper) {
296305
overflow: scroll !important;
297-
max-height: calc(40vh - 50px);
306+
max-height: calc(30vh - 50px);
298307
padding-left: 10px;
299308
padding-bottom: 10px;
300309
}
301310
311+
#rich-workspace.focus:deep(.editor__content-wrapper) {
312+
max-height: calc(40vh - 50px);
313+
}
314+
302315
#rich-workspace:deep(.text-editor__wrapper .ProseMirror) {
303316
padding: 0px;
304317
margin: 0;

0 commit comments

Comments
 (0)