Skip to content

Commit

Permalink
fix: Avoid focus trap causing troubles with tab indent of lists
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr committed Sep 5, 2023
1 parent 9fe22e4 commit 741621a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cypress/e2e/viewer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,33 @@ describe('Open test.md in viewer', function() {
cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
})

it('Can use tab keys for list in the viewer', function() {
// This used to break with the focus trap that the viewer modal has
cy.openFile('empty.md')

cy.getContent()
.type('- test{enter}')

// Cypress does not have native tab key support, though this seems to work
// for triggering the key handler of tiptap
// https://github.com/cypress-io/cypress/issues/311
cy.getContent()
.trigger('keydown', { keyCode: 9 })
cy.getContent()
.trigger('keyup', { keyCode: 9 })
cy.getContent()
.type('Nested list')

cy.getContent().find('ul li').should('contain', 'test')
cy.getContent().find('ul li ul li').should('contain', 'Nested list')

cy.getContent()
.trigger('keydown', { keyCode: 9, shiftKey: true })
cy.getContent()
.trigger('keyup', { keyCode: 9, shiftKey: true })

cy.getContent().find('ul li').eq(0).should('contain', 'test')
cy.getContent().find('ul li').eq(1).should('contain', 'Nested list')
})
})
7 changes: 7 additions & 0 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,16 @@ export default {

onFocus() {
this.emit('focus')

// Make sure that the focus trap doesn't catch tab keys while being in the contenteditable
window._nc_focus_trap?.[0]?.pause()
},
onBlur() {
this.emit('blur')

// Hand back focus to the previous trap
window._nc_focus_trap?.[0]?.unpause()
this.$el.focus()
},

onAddImageNode() {
Expand Down

0 comments on commit 741621a

Please sign in to comment.