Skip to content

Commit

Permalink
Add missing Alt/Option + Number keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Aug 11, 2023
1 parent 7eea326 commit 949badd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/common/keyboard-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class KeyboardManager {
}

_handleKeyDown(event, view) {
let { key } = event;
let { key, code } = event;
let ctrl = event.ctrlKey;
let cmd = event.metaKey && isMac();
let mod = ctrl || cmd;
Expand Down Expand Up @@ -110,6 +110,41 @@ export class KeyboardManager {
event.preventDefault();
this._reader.zoomReset();
}
else if (alt && code === 'Digit1') {
this._reader.toggleTool('highlight');
}
else if (alt && code === 'Digit2') {
this._reader.toggleTool('underline');
}
else if (alt && code === 'Digit3') {
this._reader.toggleTool('note');
}
else if (alt && this._reader._type === 'pdf' && code === 'Digit4') {
this._reader.toggleTool('text');
}
else if (alt && this._reader._type === 'pdf' && code === 'Digit5') {
this._reader.toggleTool('image');
}
else if (alt && this._reader._type === 'pdf' && code === 'Digit6') {
this._reader.toggleTool('ink');
}
else if (alt && this._reader._type === 'pdf' && code === 'Digit7') {
this._reader.toggleTool('eraser');
}
else if (alt
&& (
this._reader._type === 'pdf' && code === 'Digit8'
|| ['epub', 'snapshot'].includes(this._reader._type) && code === 'Digit4'
) && this._reader._state.tool.color) {
let idx = ANNOTATION_COLORS.findIndex(x => x[1] === this._reader._state.tool.color);
if (idx === ANNOTATION_COLORS.length - 1) {
idx = 0;
}
else {
idx++;
}
this._reader.setTool({ color: ANNOTATION_COLORS[idx][1] })
}
else if (['Delete', 'Backspace'].includes(key)) {
if (isTextBox(event.target) && event.target.closest('#findbar') || event.target.closest('.label-overlay')) {
return;
Expand Down
10 changes: 10 additions & 0 deletions src/common/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@ class Reader {
this._updateState({ tool });
}

toggleTool(type) {
let tool = this._state.tool;
if (tool.type === type) {
this._updateState({ tool: this._tools.pointer });
}
else {
this._updateState({ tool: this._tools[type] });
}
}

setFilter(filter) {
this._annotationManager.setFilter(filter);
}
Expand Down

0 comments on commit 949badd

Please sign in to comment.