Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new post shortcut #34

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ If you need support, please use the support forum to reach out. 🆘
* A disabled button is available in the toolbar in brand new posts
* The "Add New" button becomes clickable once your post's status is auto-draft, draft, pending, published, or any other state except new.
* You can duplicate the current post with two clicks.
* A keyboard shortcut to create a new post directly from your keyboard (Ctrl + Option + N on Mac or Alt + Shift + N on Windows)

### Upcoming Features

* A handy shortcut to create new posts from your keyboard when in the block editor
### Requirements

- WordPress 5.8+
Expand Down
5 changes: 1 addition & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ If you need support, please use the support forum to reach out. 🆘
* A disabled button is available in the toolbar in brand new posts
* The "Add New" button becomes clickable once your post's status is auto-draft, draft, pending, published, or any other state except new.
* You can duplicate the current post with two clicks.

### Upcoming Features

* A handy shortcut to create new posts from your keyboard when in the block editor
* A keyboard shortcut to create a new post directly from your keyboard (Ctrl + Option + N on Mac or Alt + Shift + N on Windows)

=== Stay Connected ===

Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import domReady from "@wordpress/dom-ready";
* Internal dependencies.
*/
import QuickPostButton from "./quick-post";
import { listenForKeyboardShortcut } from "./utils";

/**
* Let's subscribe (because I finally understand what this does better)
Expand Down Expand Up @@ -49,3 +50,5 @@ subscribe(() => {
);
});
});

document.addEventListener('keydown', listenForKeyboardShortcut);
12 changes: 12 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,15 @@ export function getPostTypeRestBase(postType) {
});
return rest_base;
}

export function listenForKeyboardShortcut(event) {
if (
// Shortcut for Mac (Ctrl + Option + N)
(event.ctrlKey && event.altKey && 78 === event.keyCode) ||
// Shortcut for Windows (Alt + Shift + N)
(event.altKey && event.shiftKey && 78 === event.keyCode)
) {
event.preventDefault();
document.querySelector('#createwithrani-quick-post-button').click();
}
}
kkoppenhaver marked this conversation as resolved.
Show resolved Hide resolved