Skip to content

Commit eee91f6

Browse files
mirkaaduth
authored andcommitted
Make ClipboardButton inside a block work correctly in Safari (#7106)
* Make ClipboardButton inside a block work in Safari * Update changelogs * Block Editor: Update "Next" to "Unreleased" per guidelines https://github.com/WordPress/gutenberg/blob/master/packages/README.md#maintaining-changelogs
1 parent 1b10520 commit eee91f6

File tree

4 files changed

+19
-26
lines changed

4 files changed

+19
-26
lines changed

packages/block-editor/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.0.0 (Unreleased)
2+
3+
### Breaking Changes
4+
5+
- `CopyHandler` will now only catch cut/copy events coming from its `props.children`, instead of from anywhere in the `document`.
6+
17
## 1.0.0 (2019-03-06)
28

39
### New Features

packages/block-editor/src/components/copy-handler/index.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
11
/**
22
* WordPress dependencies
33
*/
4-
import { Component } from '@wordpress/element';
54
import { serialize } from '@wordpress/blocks';
65
import { documentHasSelection } from '@wordpress/dom';
76
import { withDispatch } from '@wordpress/data';
87
import { compose } from '@wordpress/compose';
98

10-
class CopyHandler extends Component {
11-
constructor() {
12-
super( ...arguments );
13-
14-
this.onCopy = ( event ) => this.props.onCopy( event );
15-
this.onCut = ( event ) => this.props.onCut( event );
16-
}
17-
18-
componentDidMount() {
19-
document.addEventListener( 'copy', this.onCopy );
20-
document.addEventListener( 'cut', this.onCut );
21-
}
22-
23-
componentWillUnmount() {
24-
document.removeEventListener( 'copy', this.onCopy );
25-
document.removeEventListener( 'cut', this.onCut );
26-
}
27-
28-
render() {
29-
return null;
30-
}
9+
function CopyHandler( { children, onCopy, onCut } ) {
10+
return (
11+
<div onCopy={ onCopy } onCut={ onCut }>
12+
{ children }
13+
</div>
14+
);
3115
}
3216

3317
export default compose( [

packages/edit-post/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
* Expose the `className` property to style the `PluginSidebar` component.
66

77
### Bug Fixes
8-
- Fix 'save' keyboard shortcut not functioning in the Code Editor.
8+
9+
- Fix 'save' keyboard shortcut not functioning in the Code Editor.
10+
- Prevent `ClipboardButton` from incorrectly copying a serialized block string instead of the intended text in Safari.
911

1012
## 3.1.7 (2019-01-03)
1113

packages/edit-post/src/components/visual-editor/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ function VisualEditor() {
2626
return (
2727
<BlockSelectionClearer className="edit-post-visual-editor editor-styles-wrapper">
2828
<VisualEditorGlobalKeyboardShortcuts />
29-
<CopyHandler />
3029
<MultiSelectScrollIntoView />
3130
<WritingFlow>
3231
<ObserveTyping>
33-
<PostTitle />
34-
<BlockList />
32+
<CopyHandler>
33+
<PostTitle />
34+
<BlockList />
35+
</CopyHandler>
3536
</ObserveTyping>
3637
</WritingFlow>
3738
<_BlockSettingsMenuFirstItem>

0 commit comments

Comments
 (0)