Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] Fix/toc without transaction #6115

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cypress/e2e/SmartPicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ describe('Smart picker', () => {
.type('Heading{enter}Hello World{enter}')

cy.getContent()
.find('h1 [data-node-view-content]')
.should('have.text', 'Hello World')
.find('h1')
.should('contain.text', 'Hello World')
})

it('Insert a link with the smart picker', () => {
Expand Down
176 changes: 82 additions & 94 deletions cypress/e2e/initial.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ describe('Test state loading of documents', function() {

it('Initial content can not be undone', function() {
cy.shareFile('/test.md', { edit: true })
.then((token) => {
cy.visit(`/s/${token}`)
})
.then(() => {
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
.then(token => cy.visit(`/s/${token}`))
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')

cy.getMenu().should('be.visible')
cy.getActionEntry('undo').should('be.visible').click()
Expand All @@ -57,104 +54,95 @@ describe('Test state loading of documents', function() {
})

it('Consecutive sessions work properly', function() {
let readToken = null
let writeToken = null
cy.interceptCreate()
cy.shareFile('/test2.md')
.then((token) => {
readToken = token
cy.logout()
cy.visit(`/s/${readToken}`)
cy.wait('@create')
})
.then(() => {
// Open read only for the first time
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
cy.closeInterceptedSession(readToken)
.as('readToken')
cy.logout()
cy.get('@readToken')
.then(token => cy.visit(`/s/${token}`))
cy.wait('@create')
// Open read only for the first time
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
cy.get('@readToken')
.then(cy.closeInterceptedSession)

// Open read only for the second time
cy.reload()
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
cy.closeInterceptedSession(readToken)
// Open read only for the second time
cy.reload()
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
cy.get('@readToken')
.then(cy.closeInterceptedSession)

cy.login(user)
cy.shareFile('/test2.md', { edit: true })
.then((token) => {
writeToken = token
// Open write link and edit something
cy.visit(`/s/${writeToken}`)
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
cy.getContent()
.type('Something new {end}')
cy.intercept({ method: 'POST', url: '**/session/*/push' }).as('push')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')
cy.wait('@push')
cy.wait('@sync')
cy.closeInterceptedSession(writeToken)
cy.login(user)
cy.shareFile('/test2.md', { edit: true })
.as('writeToken')
// Open write link and edit something
cy.get('@writeToken')
.then(token => cy.visit(`/s/${token}`))
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
cy.getContent()
.type('Something new {end}')
cy.intercept({ method: 'POST', url: '**/session/*/sync' }).as('sync')
cy.wait('@sync')
cy.get('@writeToken')
.then(cy.closeInterceptedSession)

// Reopen read only link and check if changes are there
cy.visit(`/s/${readToken}`)
cy.getEditor().should('be.visible')
cy.getContent()
.find('h2').should('contain', 'Something new Hello world')
})
})
// Reopen read only link and check if changes are there
cy.get('@readToken')
.then(token => cy.visit(`/s/${token}`))
cy.getEditor().should('be.visible')
cy.getContent()
.find('h2').should('contain', 'Something new Hello world')
})

it('Load after state has been saved', function() {
let readToken = null
let writeToken = null
cy.interceptCreate()
cy.shareFile('/test3.md', { edit: true })
.then((token) => {
writeToken = token
cy.logout()
cy.visit(`/s/${writeToken}`)
})
.then(() => {
// Open a file, write and save
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
cy.getContent()
.type('Something new {end}')
cy.intercept({ method: 'POST', url: '**/session/*/save' }).as('save')
cy.get('.save-status button').click()
cy.wait('@save', { timeout: 10000 })
cy.closeInterceptedSession(writeToken)
.as('writeToken')
cy.logout()
cy.get('@writeToken')
.then(token => cy.visit(`/s/${token}`))

// Open writable file again and assert the content
cy.reload()
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Something new Hello world')
// Open a file, write and save
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Hello world')
cy.getContent()
.type('Something new {end}')
cy.intercept({ method: 'POST', url: '**/session/*/save' }).as('save')
cy.get('.save-status button').click()
cy.wait('@save', { timeout: 10000 })
cy.get('@writeToken')
.then(cy.closeInterceptedSession)

cy.login(user)
cy.shareFile('/test3.md')
.then((token) => {
readToken = token
cy.logout()
cy.visit(`/s/${readToken}`)
})
.then(() => {
// Open read only file again and assert the content
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Something new Hello world')
})
})
// Open writable file again and assert the content
cy.reload()
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Something new Hello world')

cy.login(user)
cy.shareFile('/test3.md')
.as('readToken')
cy.logout()
cy.get('@readToken')
.then(token => cy.visit(`/s/${token}`))

// Open read only file again and assert the content
cy.getEditor().should('be.visible')
cy.getContent()
.should('contain', 'Hello world')
.find('h2').should('contain', 'Something new Hello world')
})

})
30 changes: 15 additions & 15 deletions cypress/e2e/versions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ describe('Versions', () => {

cy.get('[data-files-versions-versions-list] li a').eq(1).click()
cy.get('.viewer__content #read-only-editor')
.find('h1 [data-node-view-content]')
.should('have.text', 'V2')
.find('h1')
.should('contain.text', 'V2')

cy.get('[data-files-versions-versions-list] li a').eq(2).click()
cy.get('.viewer__content #read-only-editor')
.find('h1 [data-node-view-content]')
.should('have.text', 'V1')
.find('h1')
.should('contain.text', 'V1')

cy.get('[data-files-versions-versions-list] li a').eq(0).click()
cy.getContent()
.find('h1 [data-node-view-content]')
.should('have.text', 'V3')
.find('h1')
.should('contain.text', 'V3')
})
})

Expand All @@ -64,18 +64,18 @@ describe('Versions', () => {

cy.get('[data-files-versions-versions-list] li a').eq(1).click()
cy.get('.viewer__content #read-only-editor')
.find('h1 [data-node-view-content]')
.should('have.text', 'V2')
.find('h1')
.should('contain.text', 'V2')

cy.get('[data-files-versions-versions-list] li a').eq(2).click()
cy.get('.viewer__content #read-only-editor')
.find('h1 [data-node-view-content]')
.should('have.text', 'V1')
.find('h1')
.should('contain.text', 'V1')

cy.get('[data-files-versions-versions-list] li a').eq(0).click()
cy.getContent()
.find('h1 [data-node-view-content]')
.should('have.text', 'V3')
.find('h1')
.should('contain.text', 'V3')

cy.getContent()
.type('Hello')
Expand Down Expand Up @@ -109,11 +109,11 @@ describe('Versions', () => {
.click()

cy.get('.viewer__content #read-only-editor')
.find('h1 [data-node-view-content]')
.should('have.text', 'V1')
.find('h1')
.should('contain.text', '#V1')

cy.get('.viewer__content .viewer__file--active .ProseMirror')
.find('h1 [data-node-view-content]')
.find('h1')
.should('contain.text', 'V3')
})
})
Expand Down
5 changes: 4 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,10 @@ export default {
this.document = document

this.syncError = null
this.$editor.setEditable(!this.readOnly)
const editable = !this.readOnly
if (this.$editor.isEditable !== editable) {
this.$editor.setEditable(editable)
}
},

onSync({ steps, document }) {
Expand Down
25 changes: 25 additions & 0 deletions src/css/prosemirror.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,34 @@ div.ProseMirror {
}

> h1,h2,h3,h4,h5,h6 {
position: relative;

&:first-child {
margin-top: 0;
}

.heading-anchor[contenteditable="false"] {
// Shrink clickable area of anchor permalinks to not overlay the heading
width: 1em;
opacity: 0;
padding: 0;
left: -1em;
bottom: 0;
font-size: max(1em, 16px);
position: absolute;
text-decoration: none;
transition-duration: .15s;
transition-property: opacity;
transition-timing-function: cubic-bezier(.4,0,.2,1);
}

&:hover .heading-anchor {
opacity: 0.5!important;
}

&:focus-visible {
outline: none;
}
}

a {
Expand Down
31 changes: 0 additions & 31 deletions src/nodes/Heading/HeadingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,3 @@ export default {
},
}
</script>

<style lang="scss">
div.ProseMirror {
/* Anchor links */
h1,h2,h3,h4,h5,h6 {
position: relative;
.heading-anchor[contenteditable="false"] {
// Shrink clickable area of anchor permalinks to not overlay the heading
width: 1em;
opacity: 0;
padding: 0;
left: -1em;
bottom: 0;
font-size: max(1em, 16px);
position: absolute;
text-decoration: none;
transition-duration: .15s;
transition-property: opacity;
transition-timing-function: cubic-bezier(.4,0,.2,1);
}

&:hover .heading-anchor {
opacity: 0.5!important;
}

&:focus-visible {
outline: none;
}
}
}
</style>