Skip to content

Commit

Permalink
Copy-markers clipboard mechanism refactor (#16005)
Browse files Browse the repository at this point in the history
Other (clipboard): By default, markers will not be copied if they are only partially selected.
Internal (clipboard): Introduced `duplicateOnPaste` and `copyPartiallySelected` options to the marker clipboard configuration. Closes #15966.
Fix (engine): Copying the content with markers will no longer trigger the `change:data` event. Closes #15943.
Tests (clipboard): Added missing tests for pasting duplicated markers in the table package.
  • Loading branch information
Mati365 committed Mar 25, 2024
1 parent d03f00a commit 39a7791
Show file tree
Hide file tree
Showing 11 changed files with 927 additions and 478 deletions.
294 changes: 199 additions & 95 deletions packages/ckeditor5-clipboard/src/clipboardmarkersutils.ts

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions packages/ckeditor5-clipboard/src/clipboardpipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,15 @@ export default class ClipboardPipeline extends Plugin {
method: 'copy' | 'cut' | 'dragstart'
): void {
const clipboardMarkersUtils: ClipboardMarkersUtils = this.editor.plugins.get( 'ClipboardMarkersUtils' );
const documentFragment = clipboardMarkersUtils._copySelectedFragmentWithMarkers( method, selection );

this.fire<ClipboardOutputTransformationEvent>( 'outputTransformation', {
dataTransfer,
content: documentFragment,
method
this.editor.model.enqueueChange( { isUndoable: method === 'cut' }, () => {
const documentFragment = clipboardMarkersUtils._copySelectedFragmentWithMarkers( method, selection );

this.fire<ClipboardOutputTransformationEvent>( 'outputTransformation', {
dataTransfer,
content: documentFragment,
method
} );
} );
}

Expand Down Expand Up @@ -275,11 +278,7 @@ export default class ClipboardPipeline extends Plugin {
}, { priority: 'low' } );

this.listenTo<ClipboardContentInsertionEvent>( this, 'contentInsertion', ( evt, data ) => {
clipboardMarkersUtils._setUniqueMarkerNamesInFragment( data.content );
}, { priority: 'highest' } );

this.listenTo<ClipboardContentInsertionEvent>( this, 'contentInsertion', ( evt, data ) => {
data.resultRange = model.insertContent( data.content );
data.resultRange = clipboardMarkersUtils._pasteFragmentWithMarkers( data.content );
}, { priority: 'low' } );
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ckeditor5-clipboard/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export {

export {
default as ClipboardMarkersUtils,
type ClipboardMarkerRestrictionsPreset,
type ClipboardMarkerRestrictedAction
type ClipboardMarkerRestrictedAction,
type ClipboardMarkerConfiguration
} from './clipboardmarkersutils.js';

export type {
Expand Down
Loading

0 comments on commit 39a7791

Please sign in to comment.