Skip to content
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

Merged
merged 2 commits into from
Aug 27, 2024
Merged

Fix focusing block widgets inside multi root editor #16892

merged 2 commits into from
Aug 27, 2024

Conversation

Mati365
Copy link
Member

@Mati365 Mati365 commented Aug 9, 2024

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

Copy link
Contributor

@niegowski niegowski left a 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:

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! );
}

@Mati365
Copy link
Member Author

Mati365 commented Aug 13, 2024

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 element.childCount check.

bug.mp4

Comment on lines 657 to 642

/* istanbul ignore next -- @preserve */
return false;
}

Copy link
Member Author

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.

Copy link
Contributor

@niegowski niegowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review.

packages/ckeditor5-engine/src/view/view.ts Outdated Show resolved Hide resolved
@Mati365
Copy link
Member Author

Mati365 commented Aug 21, 2024

@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?
Copy link
Contributor

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.

@Mati365 Mati365 merged commit 06f8520 into master Aug 27, 2024
8 checks passed
@Mati365 Mati365 deleted the ck/16806 branch August 27, 2024 07:36
@kubaklatt
Copy link

It is not a regression, but I managed to find two more scenarios that cause identical problem on Safari - #16978

@charlttsie
Copy link
Contributor

The issue still reproduces on Chrome when using tab to switch to a root with a block widget only - #16981

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-root editor: cannot focus root which has only block widget inside
4 participants