Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

T/42: Various issues when dropping or inserting files. SRP in the command #47

Merged
merged 8 commits into from
Jul 27, 2017

Conversation

Reinmar
Copy link
Member

@Reinmar Reinmar commented Jul 26, 2017

Suggested merge commit message (convention)

Fix: Fixed two issues related to dropping images. First, when dropping a file into an empty paragraph, that paragraph should be replaced with that image. Second, drop position should be read correctly when the editor is focused upon drop. Closes ckeditor/ckeditor5#2814. Closes ckeditor/ckeditor5#2802.

BREAKING CHANGE: UploadImageCommand doesn't optimize the drop position itself anymore. Instead, a separate findOptimalInsertionPosition() function was introduced.

BREAKING CHANGE: UploadImageCommand doesn't verify the type of file anymore. This needs to be done by the caller.


Additional information

I started with minimal changes, but it soon turned out that they lead to a lot more changes. I added some missing tests and it's possible that I actually fixed a few more bugs, but I didn't check if those things didn't work in the past.

@Reinmar Reinmar changed the title T/42: SRP all around T/42: Various issues when dropping or inserting files. SRP in the command Jul 26, 2017
src/utils.js Outdated
@@ -19,3 +21,47 @@ export function isImageType( file ) {
return types.test( file.type );
}

/**
* Returns a model position which is optimal (in terms of UX) for inserting and image.
Copy link

Choose a reason for hiding this comment

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

for inserting and image?

Copy link
Member Author

@Reinmar Reinmar Jul 27, 2017

Choose a reason for hiding this comment

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

"an image" ofc. I'll fix it.

src/utils.js Outdated
/**
* Returns a model position which is optimal (in terms of UX) for inserting and image.
*
* For instance, if a selection is in a middle of a paragraph, position before this paragraph
Copy link

Choose a reason for hiding this comment

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

"For instance", and then you described all cases ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

No, I didn't. Element selection, edge cases like no blocks, etc.

const selectedElement = selection.getSelectedElement();

if ( selectedElement ) {
return ModelPosition.createAfter( selectedElement );
Copy link

Choose a reason for hiding this comment

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

Comment what case it is?

Copy link
Member Author

Choose a reason for hiding this comment

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

The code reads so easily that I don't know what else you can write. If there's some element selected, return position after this selected element. It's nearly 1:1 to natural language :D

@pjasiun
Copy link

pjasiun commented Jul 27, 2017

The code looks and works great. After you update docs and comments you can merge this PR.

@Reinmar Reinmar merged commit fec452d into master Jul 27, 2017
@Reinmar Reinmar deleted the t/42 branch July 27, 2017 15:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants