-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[Multi-selection]: Copy/cut partial selected blocks #40098
Conversation
Size Change: +371 B (0%) Total Size: 1.23 MB
ℹ️ View Unchanged
|
I think it's expected behavior for text editors to merge |
Yes, we'd definitely want to trigger a merge for cutting. |
if ( isFullySelected && ! expandSelectionIsNeeded ) { | ||
removeBlocks( selectedBlockClientIds ); | ||
} else { | ||
__unstableDeleteSelection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to handle how merging will be performed(forward or not)? This is defined in other cases explicitly by checking the pressed key(Escape or Delete). Should we decide based on where the selection starts and make this as a target to merge? --cc @mtias
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question to raise, but IMO cutting isn't a directional operation in the minds of users. I'd stick with a plain (isForward: false
) deletion.
*/ | ||
import { store as blockEditorStore } from '../../store'; | ||
|
||
export default function CopyMenuItem( { blocks, onCopy } ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to partial copy from Copy
button in Block Actions? Is this something mentally mapped to copying whole blocks? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. I'd love more thoughts on this, but my instinct would always be that ⌘X, ⌘C and ⌘V should match 1:1 what similar cut/copy/paste options are surfaced in the UI. I.e. be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, I think the opposite — the copy button should say "copy blocks" and work at the full block scope, like duplicate, group, movers, and transforms since it's meta to the whole block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, I think the opposite — the copy button should say "copy blocks" and work at the full block scope, like duplicate, group, movers, and transforms since it's meta to the whole block.
This is my instinct as well. If so, we should ensure that focusing the Copy action highlights the whole block, just as for other block-wise actions.
814b455
to
b2c8c40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
if ( isFullySelected && ! expandSelectionIsNeeded ) { | ||
removeBlocks( selectedBlockClientIds ); | ||
} else { | ||
__unstableDeleteSelection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question to raise, but IMO cutting isn't a directional operation in the minds of users. I'd stick with a plain (isForward: false
) deletion.
b2c8c40
to
e8b0901
Compare
78cb2af
to
0d20c29
Compare
* [Multi-selection]: Copy/cut partial selected blocks * handle `copy` button in block actions * merge blocks on cut * partial copy from block actions only when is mergeable * update selector * revert partial selection copy in block actions menu item * add jsdoc for mapRichTextSettings util * update tests * add new e2e tests + pressKeyTimes playwright util
This was cherry-picked to the |
@ntsekouras: I don't know how I missed this in the review, but I'm experiencing a bug that I can trace back to this PR. In the screencast below, I am selecting a paragraph block, then pressing cmd+C to copy it entirely. Notice how the block flashes, but no copy occurs (as confirmed by the system clipboard). Only when I press cmd+C twice in a row do I get a successful whole-block copy. I haven't looked into it, but my immediate suspicion was that Writing Flow is incorrectly thinking that the block isn't fully selected and thus expands the selection on the first keyboard chord. copy-whole-block-expand.mov |
Confirmed by quickly patching diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js
index df2c16aa91..ca1b60fb19 100644
--- a/packages/block-editor/src/store/selectors.js
+++ b/packages/block-editor/src/store/selectors.js
@@ -925,10 +925,15 @@ export function __unstableIsFullySelected( state ) {
const selectionAnchor = getSelectionStart( state );
const selectionFocus = getSelectionEnd( state );
return (
( ! selectionAnchor.attributeKey &&
! selectionFocus.attributeKey &&
typeof selectionAnchor.offset === 'undefined' &&
typeof selectionFocus.offset === 'undefined' )
+ // Or if selection is collapsed
+ || ( selectionAnchor &&
+ selectionAnchor.clientId === selectionFocus.clientId &&
+ selectionAnchor.attributeKey === selectionFocus.attributeKey &&
+ selectionAnchor.offset === selectionFocus.offset )
);
} |
What?
Fixes: #39455
This PR implements
copy/cut
functionality for partial selections.Why?
Currently if we copy/cut when we have a partial selection, the whole blocks are affected(copied/cut). We need to only copy/cut the partial selection.
Testing Instructions
copy
button from block actions.Notes
I'll have to write e2e tests✅actions
, etc...Screenshots or screencast
Screen.Recording.2022-04-06.at.4.51.19.PM.mov