Add keyboard shortcuts to all toolbar buttons

This commit is contained in:
gsb
2026-04-29 07:23:10 +00:00
parent 1f523cbc0f
commit 8bef75e59f
3 changed files with 115 additions and 6 deletions
+48
View File
@@ -239,6 +239,54 @@ describe('ToolbarManager', () => {
});
});
describe('heading and list buttons', () => {
it('registers h1-h6', () => {
const editor = new r.Editor({ autoToolbar: false });
editor.run();
for (let i = 1; i <= 6; i++) {
const btn = editor.toolbar.buttons.get(`h${i}`);
expect(btn).toBeDefined();
expect(btn!.label).toBe(`H${i}`);
expect(btn!.shortcut).toBe(`Ctrl+${i}`);
expect(btn!.action).toBe('prefix');
}
});
it('registers ul and ol', () => {
const editor = new r.Editor({ autoToolbar: false });
editor.run();
expect(editor.toolbar.buttons.get('ul')!.shortcut).toBe('Ctrl+Shift+8');
expect(editor.toolbar.buttons.get('ol')!.shortcut).toBe('Ctrl+Shift+7');
});
});
describe('keyboard shortcuts', () => {
it('all formatting buttons have shortcuts', () => {
const editor = new r.Editor({ autoToolbar: false });
editor.run();
const expected = ['bold', 'italic', 'code', 'link', 'save'];
for (const id of expected) {
expect(editor.toolbar.buttons.get(id)!.shortcut).toBeDefined();
}
});
it('block buttons have shortcuts', () => {
const editor = new r.Editor({ autoToolbar: false });
editor.run();
expect(editor.toolbar.buttons.get('fencedCode')!.shortcut).toBe('Ctrl+Shift+E');
expect(editor.toolbar.buttons.get('blockquote')!.shortcut).toBe('Ctrl+Shift+.');
expect(editor.toolbar.buttons.get('table')!.shortcut).toBe('Ctrl+Shift+T');
expect(editor.toolbar.buttons.get('hr')!.shortcut).toBe('Ctrl+Shift+-');
});
it('editor actions have shortcuts', () => {
const editor = new r.Editor({ autoToolbar: false });
editor.run();
expect(editor.toolbar.buttons.get('toggle')!.shortcut).toBe('Ctrl+Shift+V');
expect(editor.toolbar.buttons.get('markdown')!.shortcut).toBe('Ctrl+/');
});
});
describe('save button', () => {
it('triggers editor.save()', () => {
resetDOM();