Skip to content

Commit

Permalink
refactor: if/else conditions (#1822)
Browse files Browse the repository at this point in the history
* refactor: shortcuts if/else

* fix: merge conflict
  • Loading branch information
dakshesh14 authored Aug 10, 2023
1 parent 1c6cdb8 commit 9ce85cd
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions apps/app/components/command-palette/command-pallette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,39 @@ export const CommandPalette: React.FC = () => {

const handleKeyDown = useCallback(
(e: KeyboardEvent) => {
const singleShortcutKeys = ["p", "v", "d", "h", "q", "m"];
// if on input, textarea or editor, don't do anything
if (
e.target instanceof HTMLTextAreaElement ||
e.target instanceof HTMLInputElement ||
(e.target as Element).classList?.contains("remirror-editor")
)
return;

const { key, ctrlKey, metaKey, altKey, shiftKey } = e;

if (!key) return;

const keyPressed = key.toLowerCase();
if (
!(e.target instanceof HTMLTextAreaElement) &&
!(e.target instanceof HTMLInputElement) &&
!(e.target as Element).classList?.contains("remirror-editor")
) {
if ((ctrlKey || metaKey) && keyPressed === "k") {

const cmdClicked = ctrlKey || metaKey;

if (cmdClicked) {
if (keyPressed === "k") {
e.preventDefault();
setIsPaletteOpen(true);
} else if ((ctrlKey || metaKey) && keyPressed === "c") {
if (altKey) {
e.preventDefault();
copyIssueUrlToClipboard();
}
} else if (keyPressed === "c") {
} else if (keyPressed === "c" && altKey) {
e.preventDefault();
setIsIssueModalOpen(true);
} else if ((ctrlKey || metaKey) && keyPressed === "b") {
copyIssueUrlToClipboard();
} else if (keyPressed === "b") {
e.preventDefault();
// toggleCollapsed();
store.theme.setSidebarCollapsed(!store?.theme?.sidebarCollapsed);
} else if (key === "Delete") {
toggleCollapsed();
} else if (keyPressed === "backspace") {
e.preventDefault();
setIsBulkDeleteIssuesModalOpen(true);
} else if (
singleShortcutKeys.includes(keyPressed) &&
(ctrlKey || metaKey || altKey || shiftKey)
) {
e.preventDefault();
}
} else {
if (keyPressed === "c") {
setIsIssueModalOpen(true);
} else if (keyPressed === "p") {
setIsProjectModalOpen(true);
} else if (keyPressed === "v") {
Expand All @@ -125,7 +126,7 @@ export const CommandPalette: React.FC = () => {
}
}
},
[copyIssueUrlToClipboard]
[copyIssueUrlToClipboard, toggleCollapsed]
);

useEffect(() => {
Expand Down

1 comment on commit 9ce85cd

@vercel
Copy link

@vercel vercel bot commented on 9ce85cd Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

plane-dev – ./apps/app

plane-dev.vercel.app
plane-dev-git-develop-plane.vercel.app
plane-dev-plane.vercel.app

Please sign in to comment.