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

U/juliaroldi/image editing refactor #1345

Merged
merged 25 commits into from
Oct 28, 2022

Conversation

juliaroldi
Copy link
Contributor

@juliaroldi juliaroldi commented Oct 18, 2022

Adapt Image Edit plugin to use Selection Change Event.

@juliaroldi juliaroldi marked this pull request as ready for review October 19, 2022 16:19
@JiuqingSong
Copy link
Collaborator

Generally to make the code cleaner, we can deprecate the image selection feature, and always use image selection

@juliaroldi juliaroldi marked this pull request as draft October 19, 2022 22:44
@juliaroldi juliaroldi marked this pull request as ready for review October 21, 2022 22:10
@juliaroldi juliaroldi force-pushed the u/juliaroldi/image-editing-refactor branch from 709e22a to 5de5a1c Compare October 21, 2022 22:14
@@ -34,7 +34,7 @@ export const KnownCreateElementData: Record<KnownCreateElementDataIndex, CreateE
},
[KnownCreateElementDataIndex.ImageEditWrapper]: {
tag: 'div',
style: 'width:100%;height:100%;position:relative;overflow:hidden',
style: 'width:100%;height:100%;position:relative;overflow:hidden;',
Copy link
Collaborator

Choose a reason for hiding this comment

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

curious: is this change required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it is not, beautify extension added, because I touched the file. I'll remove.

@@ -288,7 +310,7 @@ export default class ImageEdit implements EditorPlugin {
typeof operationOrSelect === 'number' ? operationOrSelect : ImageEditOperation.None;
const selectImage = typeof operationOrSelect === 'number' ? false : !!operationOrSelect;

if (this.image) {
if (!image && this.image) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why need this check? What if I select another image?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid a loop. In line 315, the image is being selected again, because we add the wrapper we remove the selection from the image, then we need to select the image again and we do this selection setEditingImage will be called, then to avoid select the image again we do not have the wrapper, unless we use setEditingImage is called with null.
When we trigger mouse we set editing to null, but if we click in another image the imageSelect plugin will select the image and then selection event will be trigger and the new image will be selected.

// Press ESC should cancel current editing operation, resume back to original edit info
this.editInfo = getEditInfoFromImage(this.image);
this.setEditingImage(
e.selectionRangeEx?.image,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You already did null check of selectionRangeEx in line 183, no need to add "?" here

e.source != ChangeSource.InsertEntity ||
(<Entity>e.data).type != IMAGE_EDIT_WRAPPER_ENTITY_TYPE
(e.source !== ChangeSource.Format && e.source !== ChangeSource.InsertEntity) ||
(<Entity>e.data)?.type != IMAGE_EDIT_WRAPPER_ENTITY_TYPE
Copy link
Collaborator

Choose a reason for hiding this comment

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

this need to be combined with the check with ChangeSource.InsertEntity, which means, if e.source is not Insert Entity, or (e.source is InsertEntity, and) entity data type is not image wrapper related.

@@ -19,7 +19,7 @@ import {
getEntityFromElement,
getEntitySelector,
getObjectKeys,
matchesSelector,
//matchesSelector,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Remove this commented line

if (onShowResizeHandle) {
onShowResizeHandle(elementData, x, y)
onShowResizeHandle(elementData, x, y);
Copy link
Contributor

Choose a reason for hiding this comment

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

elementData can be null, should we add a null check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this had to be node in another PR to enable strict mode. I didn't made any changes in this files, but the beautify extension add the semicolon

@@ -280,4 +283,11 @@ export default class CopyPastePlugin implements PluginWithState<CopyPastePluginS
table.style.removeProperty('height');
}
}

private deleteImage(editor: IEditor, imageId: string) {
const image = editor.getDocument().querySelector('#' + imageId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

use editor.queryElements() instead to avoid query image outside editor

break;

case PluginEventType.MouseDown:
this.setEditingImage(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This works. But I think that is what I concerned about current implementation. We can go with this for now, and revisit it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can change this implementation, but we would have to change the select function to trigger selection change event, when no range is selected.

@juliaroldi juliaroldi merged commit 9d8e7af into master Oct 28, 2022
@juliaroldi juliaroldi deleted the u/juliaroldi/image-editing-refactor branch October 28, 2022 13:58
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.

3 participants