Skip to content

Commit

Permalink
Fix Cmd-i and Cmd-b blurring text field and focusing comment field
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Sep 29, 2023
1 parent 939b35f commit ebd7ebb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/common/components/common/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ function ToolbarButton({ action, onCommand }) {

function Toolbar({ onCommand }) {
let toolbarRef = useRef();
let activeRef = useRef(false);

useLayoutEffect(() => {
update();
Expand All @@ -197,6 +198,9 @@ function Toolbar({ onCommand }) {
});

function handleKeyDown(event) {
if (!activeRef.current) {
return;
}
let { key } = event;
let ctrl = event.ctrlKey;
let cmd = event.metaKey;
Expand Down Expand Up @@ -228,13 +232,15 @@ function Toolbar({ onCommand }) {
let selection = window.getSelection();
if (!selection || selection.isCollapsed) {
toolbarRef.current.style.display = 'none';
activeRef.current = false;
return;
}
let range = selection.getRangeAt(0);
let selectionRect = range.getBoundingClientRect();
let editorNode = range.startContainer.parentNode.closest('.editor');
if (!editorNode.parentNode.contains(toolbarRef.current)) {
toolbarRef.current.style.display = 'none';
activeRef.current = false;
return;
}
let editorRect = editorNode.getBoundingClientRect();
Expand All @@ -245,6 +251,7 @@ function Toolbar({ onCommand }) {
}
toolbarRef.current.style.display = 'flex';
toolbarRef.current.style.top = top + 'px';
activeRef.current = true;
}

return (
Expand Down

0 comments on commit ebd7ebb

Please sign in to comment.