Skip to content

Commit

Permalink
Add support for bold and italic keyboard shortcuts on newer Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Aug 22, 2023
1 parent e26f79b commit af16c66
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/common/components/common/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,34 @@ function Toolbar({ onCommand }) {
}, []);

useEffect(() => {
document.addEventListener('keydown', handleKeyDown);
document.addEventListener('selectionchange', handleSelectionChange);
document.addEventListener('scroll', handleScroll, true);
return () => {
document.removeEventListener('keydown', handleKeyDown);
document.removeEventListener('selectionchange', handleSelectionChange);
document.removeEventListener('scroll', handleScroll, true);
};
});

function handleKeyDown(event) {
let { key } = event;
let ctrl = event.ctrlKey;
let cmd = event.metaKey;
let shift = event.shiftKey;
let alt = event.altKey;
let mod = ctrl || cmd;
if (!shift && !alt && mod) {
if (key === 'b') {
onCommand('bold');
}
else if (key === 'i') {
onCommand('italic');
}
event.preventDefault();
}
}

function handleSelectionChange() {
update();
}
Expand Down

0 comments on commit af16c66

Please sign in to comment.