Skip to content

Commit

Permalink
Fix broken clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Aug 16, 2024
1 parent 46c6bbf commit 2e0562d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/ckeditor5-clipboard/tests/dragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2436,7 +2436,8 @@ describe( 'Drag and Drop', () => {
const eventData = prepareEventData( model.document.selection.getLastPosition(), domTarget );

viewDocument.fire( 'mousedown', {
...eventData
...eventData,
preventDefault
} );

viewDocument.fire( 'dragstart', {
Expand Down
5 changes: 2 additions & 3 deletions packages/ckeditor5-engine/src/view/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,11 @@ export function getPointViewRange(
rangeOffset?: number;
}
): Range | null {
const domDoc = ( domEvent.target as HTMLElement ).ownerDocument;

if ( !domDoc ) {
if ( !domEvent.target ) {
return null;
}

const domDoc = ( domEvent.target as HTMLElement ).ownerDocument;
const x = domEvent.clientX;
const y = domEvent.clientY;
let domRange;
Expand Down
14 changes: 8 additions & 6 deletions packages/ckeditor5-widget/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,16 @@ export default class Widget extends Plugin {
return range && range.start.parent;
} )();

// If the click target is a text node, we need to get the parent element.
const clickElementFromPoint = clickTargetFromPoint && clickTargetFromPoint.is( '$text' ) ?
clickTargetFromPoint.parent : clickTargetFromPoint;
// If the click target is a text node, we need to abort heuristics. This is because the text node
// can be draggable and focusing the parent node breaks the drag and drop.
if ( !clickTargetFromPoint || clickTargetFromPoint.is( '$text' ) ) {
return;
}

// If the element is a widget, we need to select the widget itself otherwise we need to select the first ancestor widget.
if ( clickElementFromPoint && clickElementFromPoint.is( 'element' ) ) {
element = isWidget( clickElementFromPoint ) ?
clickElementFromPoint : clickElementFromPoint.findAncestor( isWidget );
if ( clickTargetFromPoint && clickTargetFromPoint.is( 'element' ) ) {
element = isWidget( clickTargetFromPoint ) ?
clickTargetFromPoint : clickTargetFromPoint.findAncestor( isWidget );
}

if ( !element ) {
Expand Down

0 comments on commit 2e0562d

Please sign in to comment.