Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ socket.onmessage = (e) => store.applyDiff(JSON.parse(e.data), 'remote')
| `⌘+` / `⌘−` | Zoom in / out |
| `⌫` / `⇧⌘⌫` | Delete selection / clear the board (undoable) |
| `Enter` / `Esc` | Edit text / done |
| `?` | Show this list on the board |

## Repository

Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,8 @@ export class Editor {
else this.setTool('select')
return
}
if (k === '?') { e.preventDefault(); this.emit('help'); return }
// the UI layer listens for this and toggles the shortcuts overlay
if (k === '?') { e.preventDefault(); this.emit('help'); return }
// wipe the board — two modifiers deep, and undoable like any other edit
if (meta && e.shiftKey && (k === 'delete' || k === 'backspace')) {
e.preventDefault()
Expand Down
37 changes: 37 additions & 0 deletions packages/core/test/editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,40 @@ describe('createQuickdraw UI', () => {
c2.remove()
})
})

describe('keyboard help overlay', () => {
const press = (board, key) =>
board.editor._keyDown({ key, shiftKey: true, metaKey: false, ctrlKey: false, preventDefault() {} })

it('? toggles the overlay, Esc closes it, destroy tears it down', () => {
const c2 = document.createElement('div')
document.body.appendChild(c2)
const board = createQuickdraw({ container: c2 })
const open = () => !!c2.querySelector('.qd-help-backdrop')

press(board, '?')
expect(open()).toBe(true)
expect(c2.querySelectorAll('.qd-help-row').length).toBeGreaterThan(20)
press(board, '?')
expect(open()).toBe(false)

press(board, '?')
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
expect(open()).toBe(false)

press(board, '?')
board.destroy()
expect(document.querySelector('.qd-help-backdrop')).toBe(null)
c2.remove()
})

it('stays quiet on a readonly board', () => {
const c2 = document.createElement('div')
document.body.appendChild(c2)
const board = createQuickdraw({ container: c2, readonly: true })
press(board, '?')
expect(c2.querySelector('.qd-help-backdrop')).toBe(null)
board.destroy()
c2.remove()
})
})
2 changes: 1 addition & 1 deletion packages/core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export interface EditorOptions {

export type EditorEvent =
| 'change' | 'history' | 'camera' | 'tool' | 'styles' | 'selection'
| 'theme' | 'grid' | 'edit' | 'scribbles' | 'penmode'
| 'theme' | 'grid' | 'edit' | 'scribbles' | 'penmode' | 'help'

/**
* The editor: camera, tools, selection, input and rendering over a Store.
Expand Down
Loading