Skip to content

Commit

Permalink
prevent event discovery on the editor wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Nov 30, 2018
1 parent 2a9d9a4 commit 37016c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import { withSelect } from '@wordpress/data';
import { EditorProvider, ErrorBoundary, PostLockedModal } from '@wordpress/editor';
import { StrictMode } from '@wordpress/element';
import { KeyboardShortcuts } from '@wordpress/components';

/**
* Internal dependencies
*/
import preventEventDiscovery from './prevent-event-discovery';
import Layout from './components/layout';

function Editor( {
Expand Down Expand Up @@ -38,6 +41,7 @@ function Editor( {
>
<ErrorBoundary onError={ onError }>
<Layout />
<KeyboardShortcuts shortcuts={ preventEventDiscovery } />
</ErrorBoundary>
<PostLockedModal />
</EditorProvider>
Expand Down
17 changes: 17 additions & 0 deletions packages/edit-post/src/prevent-event-discovery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
't a l e s o f g u t e n b e r g': ( event ) => {
if (
! document.activeElement.classList.contains( 'edit-post-visual-editor' ) &&
document.activeElement !== document.body
) {
return;
}

event.preventDefault();
wp.data.dispatch( 'core/editor' ).insertBlock(
wp.blocks.createBlock( 'core/paragraph', {
content: '🐡🐢🦀🐤🦋🐘🐧🐹🦁🦄🦍🐼🐿🎃🐴🐝🐆🦕🦔🌱🍇π🍌🐉💧🥨🌌🍂🍠🥦🥚🥝🎟🥥🥒🛵🥖🍒🍯🎾🎲🐺🐚🐮⌛️',
} )
);
},
};

0 comments on commit 37016c5

Please sign in to comment.