-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed as not planned
Closed as not planned
Copy link
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
Description
In a typography correction plugin, I need to listen for the Paste event to process blocks when the user pastes content. This was working until recently but no longer functions.
I noticed that by enabling Custom Fields in Preferences, I could listen to the event again.
To rule out the possibility that my code is causing the issue, I tested a simple script with which I can reproduce the problem.
Step-by-step reproduction instructions
- Launch WordPress in its latest version on PHP 8.x with Gutenberg (even using the latest PRs).
- Create a simple plugin with the following PHP and JS code.
- Upload the plugin and activate it.
- Create a new post and open the console.
- Paste text into the editor and see that no events are logged in the console.
- Enable Custom Fields in Preferences and paste text into the editor again.
- Notice that the event is now being listened to and appears in the console.
<?php
/*
Plugin Name: pasteEventListenerPlugin
Description: A simple plugin to load a JS script in the Gutenberg block editor to display something
Version: 1.0
Author: Nobody
*/
defined( 'ABSPATH' ) || exit;
function paste_event_listener_plugin_enqueue_script() {
// Enqueue the script only in the block editor
wp_enqueue_script(
'paste-event-listener-plugin',
plugin_dir_url( __FILE__ ) . 'paste-event-listener-plugin.js',
array( 'wp-blocks', 'wp-element', 'wp-editor' ),
filemtime( plugin_dir_path( __FILE__ ) . 'paste-event-listener-plugin.js' )
);
}
add_action( 'enqueue_block_editor_assets', 'paste_event_listener_plugin_enqueue_script' );wp.domReady( () => {
// Intercept clipboard paste
var editorElement = document.querySelector('#editor');
if (editorElement) {
editorElement.addEventListener('paste', function(e) {
console.log(e);
} );
}
} );Screenshots, screen recording, code snippet
Environment info
WP 6.5.3
Gutenberg PR 62144
PHP 8.3
Chrome
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Metadata
Metadata
Assignees
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
