-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Fix focusing block widgets inside multi root editor #16892
Conversation
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.
Widgets have a dedicated handling of the selection. The DOM selection is handled differently while a widget is selected, it's anchored in a fake selection container. I feel like the fix should be located in this handler of the widget:
ckeditor5/packages/ckeditor5-widget/src/widget.ts
Lines 276 to 320 in dcb087f
private _onMousedown( eventInfo: EventInfo, domEventData: DomEventData<MouseEvent> ) { | |
const editor = this.editor; | |
const view = editor.editing.view; | |
const viewDocument = view.document; | |
let element: ViewElement | null = domEventData.target; | |
// If triple click should select entire paragraph. | |
if ( domEventData.domEvent.detail >= 3 ) { | |
if ( this._selectBlockContent( element ) ) { | |
domEventData.preventDefault(); | |
} | |
return; | |
} | |
// Do nothing for single or double click inside nested editable. | |
if ( isInsideNestedEditable( element ) ) { | |
return; | |
} | |
// If target is not a widget element - check if one of the ancestors is. | |
if ( !isWidget( element ) ) { | |
element = element.findAncestor( isWidget ); | |
if ( !element ) { | |
return; | |
} | |
} | |
// On Android selection would jump to the first table cell, on other devices | |
// we can't block it (and don't need to) because of drag and drop support. | |
if ( env.isAndroid ) { | |
domEventData.preventDefault(); | |
} | |
// Focus editor if is not focused already. | |
if ( !viewDocument.isFocused ) { | |
view.focus(); | |
} | |
// Create model selection over widget. | |
const modelElement = editor.editing.mapper.toModelElement( element ); | |
this._setSelectionOverElement( modelElement! ); | |
} |
Unfortunately it's still a bit buggy :/ It looks like, while cursor is properly placed in element, the table is receiving incorrectly focus. Probably related to bug.mp4 |
|
||
/* istanbul ignore next -- @preserve */ | ||
return false; | ||
} | ||
|
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.
It looks like incorrect istanbul
report, because return false;
is reached during the tests.
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.
Partial review.
@niegowski I moved function to utils. Can you take a look? |
|
||
currentElement = currentElement.parent; | ||
// TODO There was a comment about broken drag&drop but without further explanation. What was happening exactly? |
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.
Please explain what the original comment was about.
It is not a regression, but I managed to find two more scenarios that cause identical problem on Safari - #16978 |
The issue still reproduces on Chrome when using tab to switch to a root with a block widget only - #16981 |
Suggested merge commit message (convention)
Fix (editor-multi-root): No longer lose selection on clicking editable containing only one block element. Closes #16806
Additional information
I adjusted multi-root demos with additional plugins to make debugging block items easier.
Debug log: #16806 (comment)
Before
chrome-selection-before-2024-08-09_09.00.01.mp4
After
chrome-selection-fix-2024-08-09_08.57.31.mp4
chrome-selection-images-2024-08-09_11.02.41.mp4