Skip to content

Commit 9a07509

Browse files
azulJulien Veyssier
authored andcommitted
fix: 2020 let heading menu overflow workspace
* roll back parts of #1903 that broke it again. * Calculate top of menububble based on scrollHeight of content-wrapper. * Always display menububble below selected line. This will make it less likely to conflict with the menubar or mobile copy and paste toolbars. * Add cypress tests for the workspace. Signed-off-by: Azul <azul@riseup.net>
1 parent cec776f commit 9a07509

5 files changed

Lines changed: 157 additions & 13 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* @copyright Copyright (c) 2021 Azul <azul@riseup.net>
3+
*
4+
* @author Azul <azul@riseup.net>
5+
*
6+
* @license GNU AGPL version 3 or any later version
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
24+
import { randHash } from '../utils/'
25+
const randUser = randHash()
26+
27+
describe('Workspace', function() {
28+
29+
before(function() {
30+
cy.nextcloudCreateUser(randUser, 'password')
31+
})
32+
33+
beforeEach(function() {
34+
cy.login(randUser, 'password')
35+
cy.visit('/apps/files')
36+
// isolate tests - each happens in it's own folder
37+
cy.createFolder(Cypress.currentTest.title)
38+
cy.openFile(Cypress.currentTest.title)
39+
})
40+
41+
it('adds a Readme.md', function() {
42+
cy.get('#fileList').should('not.contain', 'Readme.md')
43+
openWorkspace()
44+
.type('Hello')
45+
.should('contain', 'Hello')
46+
cy.get('#fileList').should('contain', 'Readme.md')
47+
})
48+
49+
it('formats text', function() {
50+
openWorkspace()
51+
.type('Format me')
52+
.type('{selectall}')
53+
;[['bold', 'strong'], ['italic', 'em'], ['strike', 's']]
54+
.forEach(([button, tag]) => {
55+
menuButton(button)
56+
.click()
57+
.should('have.class', 'is-active')
58+
cy.get(`.ProseMirror ${tag}`).should('contain', 'Format me')
59+
menuButton(button)
60+
.click()
61+
.should('not.have.class', 'is-active')
62+
})
63+
})
64+
65+
it('links via menububble', function() {
66+
openWorkspace()
67+
.type('Nextcloud')
68+
.type('{selectall}')
69+
menuBubbleButton('link').click()
70+
cy.get('.menububble input').type('https://nextcloud.com{enter}')
71+
cy.get('.ProseMirror a')
72+
.should('contain', 'Nextcloud')
73+
.should('be.visible')
74+
cy.get('.ProseMirror a').invoke('attr', 'href')
75+
.should('include', 'https://nextcloud.com')
76+
cy.window().then((win) => {
77+
cy.stub(win, 'open').as('windowOpen')
78+
})
79+
cy.get('.ProseMirror a').click()
80+
cy.get('@windowOpen').should('be.calledWith', 'https://nextcloud.com/')
81+
cy.get('.ProseMirror').type('{selectall}')
82+
menuBubbleButton('link').click()
83+
cy.get('.menububble input').type('/team{enter}')
84+
cy.get('.ProseMirror a').click()
85+
cy.get('@windowOpen').should('be.calledWith', 'https://nextcloud.com/team')
86+
})
87+
88+
it('creates headings via submenu', function() {
89+
openWorkspace()
90+
.type('Heading')
91+
.type('{selectall}')
92+
;['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].forEach((heading) => {
93+
menuButton('h1').click()
94+
submenuButton(heading).click()
95+
menuButton(heading).should('have.class', 'is-active')
96+
cy.get(`.ProseMirror ${heading}`)
97+
.should('contain', 'Heading')
98+
menuButton(heading).click()
99+
submenuButton(heading).click()
100+
menuButton('h1').should('not.have.class', 'is-active')
101+
})
102+
})
103+
104+
})
105+
106+
const menuButton = (name) => {
107+
return cy.get(`#editor button.icon-${name}`)
108+
}
109+
110+
const submenuButton = (name) => {
111+
return cy.get(`#editor button .icon-${name}`)
112+
}
113+
114+
const menuBubbleButton = submenuButton
115+
116+
const openWorkspace = () => {
117+
cy.get('#rich-workspace').click()
118+
cy.get('#editor .content-wrapper').click()
119+
return cy.get('#rich-workspace .ProseMirror')
120+
}

cypress/runLocal.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,21 @@ then
1616
fi
1717

1818
# start server if it's not running yet
19-
if $(npm bin)/wait-on -i 500 -t 1000 $CYPRESS_baseUrl
19+
if $(npm bin)/wait-on -i 500 -t 1000 $CYPRESS_baseUrl 2> /dev/null
2020
then
2121
echo Server is up at $CYPRESS_baseUrl
2222
else
23+
echo No server reached at $CYPRESS_baseUrl - starting containers.
2324
docker-compose up -d
24-
$(npm bin)/wait-on -i 500 -t 240000 $CYPRESS_baseUrl || ( docker-compose logs ; exit 1 )
25-
docker-compose exec -T nextcloud bash /var/www/html/apps/text/cypress/server.sh
25+
if $(npm bin)/wait-on -i 500 -t 240000 $CYPRESS_baseUrl 2> /dev/null
26+
then
27+
docker-compose exec -T nextcloud bash /var/www/html/apps/text/cypress/server.sh
28+
else
29+
echo Waiting for $CYPRESS_baseUrl timed out.
30+
echo Container logs:
31+
docker-compose logs
32+
exit 1
33+
fi
2634
fi
2735

2836
(cd .. && $(npm bin)/cypress $@)

src/components/EditorWrapper.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</div>
5656
<slot name="header" />
5757
</MenuBar>
58-
<div class="content-wrapper">
58+
<div ref="wrapper" class="content-wrapper">
5959
<MenuBubble v-if="!readOnly && isRichEditor"
6060
:editor="tiptap"
6161
:file-path="relativePath" />

src/components/MenuBubble.vue

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,21 @@ export default {
107107
isUsingDirectEditing: loadState('text', 'directEditingToken', null) !== null,
108108
}
109109
},
110+
computed: {
111+
112+
// Minimum left value for the bubble so that it stays inside the editor.
113+
// the width of the menububble changes depending on its state
114+
// during the bubblePosition calculation it has not been rendered yet.
115+
// so we have to hard code the minimum.
116+
minLeft() {
117+
if (this.linkMenuIsActive || !this.editor.isActive.link()) {
118+
return 150
119+
} else {
120+
return 225
121+
}
122+
},
123+
124+
},
110125
methods: {
111126
showLinkMenu(attrs) {
112127
this.linkUrl = attrs.href
@@ -159,15 +174,14 @@ export default {
159174
command({ href: null })
160175
},
161176
bubblePosition(menu) {
162-
// below the first line, above all others
163-
const vertical = menu.top < 45
164-
? { top: `${menu.top}px` }
165-
: { bottom: `${menu.bottom}px` }
177+
const wrapper = this.$parent.$refs.wrapper
178+
const left = Math.max(this.minLeft, menu.left)
166179
return {
167-
...vertical,
168-
left: `${menu.left}px`,
180+
top: `${menu.top + wrapper.scrollTop + 5}px`,
181+
left: `${left}px`,
169182
}
170183
},
184+
171185
},
172186
}
173187
</script>
@@ -231,7 +245,7 @@ export default {
231245
font: inherit;
232246
border: none;
233247
background: transparent;
234-
min-width: 150px;
248+
min-width: 250px;
235249
}
236250
}
237251
</style>

src/views/RichWorkspace.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,14 @@ export default {
213213
}
214214
215215
#rich-workspace::v-deep #editor {
216-
overflow: scroll !important;
217-
max-height: calc(40vh - 40px);
216+
overflow: visible !important;
218217
}
219218
220219
#rich-workspace::v-deep .content-wrapper {
220+
overflow: scroll !important;
221+
max-height: calc(40vh - 50px);
221222
padding-left: 10px;
223+
padding-bottom: 60px; /* ensure menububble fits below */
222224
}
223225
224226
#rich-workspace::v-deep #editor-wrapper .ProseMirror {

0 commit comments

Comments
 (0)