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

Make ClipboardButton inside a block work correctly in Safari #7106

Merged
merged 3 commits into from
Mar 21, 2019
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
6 changes: 6 additions & 0 deletions packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.0.0 (Unreleased)

### Breaking Changes

- `CopyHandler` will now only catch cut/copy events coming from its `props.children`, instead of from anywhere in the `document`.

## 1.0.0 (2019-03-06)

### New Features
Expand Down
28 changes: 6 additions & 22 deletions packages/block-editor/src/components/copy-handler/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { serialize } from '@wordpress/blocks';
import { documentHasSelection } from '@wordpress/dom';
import { withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';

class CopyHandler extends Component {
constructor() {
super( ...arguments );

this.onCopy = ( event ) => this.props.onCopy( event );
this.onCut = ( event ) => this.props.onCut( event );
}

componentDidMount() {
document.addEventListener( 'copy', this.onCopy );
document.addEventListener( 'cut', this.onCut );
}

componentWillUnmount() {
document.removeEventListener( 'copy', this.onCopy );
document.removeEventListener( 'cut', this.onCut );
}

render() {
return null;
}
function CopyHandler( { children, onCopy, onCut } ) {
return (
<div onCopy={ onCopy } onCut={ onCut }>
{ children }
</div>
);
}

export default compose( [
Expand Down
4 changes: 3 additions & 1 deletion packages/edit-post/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* Expose the `className` property to style the `PluginSidebar` component.

### Bug Fixes
- Fix 'save' keyboard shortcut not functioning in the Code Editor.

- Fix 'save' keyboard shortcut not functioning in the Code Editor.
- Prevent `ClipboardButton` from incorrectly copying a serialized block string instead of the intended text in Safari.

## 3.1.7 (2019-01-03)

Expand Down
7 changes: 4 additions & 3 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ function VisualEditor() {
return (
<BlockSelectionClearer className="edit-post-visual-editor editor-styles-wrapper">
<VisualEditorGlobalKeyboardShortcuts />
<CopyHandler />
<MultiSelectScrollIntoView />
<WritingFlow>
<ObserveTyping>
<PostTitle />
<BlockList />
<CopyHandler>
<PostTitle />
<BlockList />
</CopyHandler>
</ObserveTyping>
</WritingFlow>
<_BlockSettingsMenuFirstItem>
Expand Down