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

Throw an error when user tries to use inappropriate editor over textarea #173

Merged
merged 6 commits into from
Jun 12, 2019

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented May 7, 2019

@coveralls
Copy link

coveralls commented May 7, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling b80e923 on t/ckeditor5/1591 into b9ed5af on master.

src/editor/editor.js Outdated Show resolved Hide resolved
@msamsel
Copy link
Contributor Author

msamsel commented May 16, 2019

@pomek I've change solution to not include unnecessary promise. Thx for feedback.

@msamsel msamsel requested a review from pomek May 16, 2019 12:15
Copy link
Member

@pomek pomek left a comment

Choose a reason for hiding this comment

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

Not sure whether we should stay with _assertAllowedSourceElement or change it to _assertSourceElement but the logic inside the method looks good.

* @param {HTMLElement|String} sourceElementOrData The DOM element that will be the source for the created editor
* or the editor's initial data.
*/
static _assertAllowedSourceElement( sourceElementOrData ) {
Copy link
Member

Choose a reason for hiding this comment

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

You added this method to the base editor. But there are editor types where textarea is a valid source element. So, in other words, this method is not that generic and should either be made more specific or moved out of here.

The other problem with it is that it does not actually check allowed elements yet. It checks only the textarea case. So not only this method is not defined in the right place, but also it's called incorrectly.

I think the easiest solution here would be to have this duplicated – there's very little code here. The only thing which needs to be DRY-ed is the error message, so we could keep it here and document in the places where we'll be firing it that it's defined here.

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've move element check directly to create methods of each class. It's going to be similar to checks for initial data:
https://github.com/ckeditor/ckeditor5-editor-balloon/blob/d5c4162fe018c65604a59c5cd0d0b0f5e53c6574/src/ballooneditor.js#L209-L212

* or the editor's initial data.
*/
static _assertAllowedSourceElement( sourceElementOrData ) {
if ( isElement( sourceElementOrData ) && sourceElementOrData.tagName.toLowerCase() === 'textarea' ) {
Copy link
Member

Choose a reason for hiding this comment

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

Why toLowerCase()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's completely unnecessary here.

@msamsel msamsel requested a review from Reinmar May 22, 2019 11:39
@msamsel msamsel requested a review from jodator May 30, 2019 13:17
@msamsel
Copy link
Contributor Author

msamsel commented May 30, 2019

@jodator I asked you for review, as @Reinmar won't have time in near time to make another review of this PR.
Please notice that main changes are located in related repositories and PRs.

@jodator
Copy link
Contributor

jodator commented Jun 10, 2019

I've extracted this one: ckeditor/ckeditor5#1806 to review docs later on.

Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

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

@msamsel I found that all that code is practically duplicated over those 3 repositories. I think that it would make sense to create a single assertion method for that in core & import it in proper editors. Something similarly to attachToForm() method from core/src/editor/utils.

Maybe assertNotUsedOverTextareaElement( initialDataOrElement )? But if you have better name please propose something :D Also move the error docs there.

It also makes sense to extract this if we ever add another editor type.

@msamsel
Copy link
Contributor Author

msamsel commented Jun 12, 2019

@msamsel I found that all that code is practically duplicated over those 3 repositories. I think that it would make sense to create a single assertion method for that in core & import it in proper editors. Something similarly to attachToForm() method from core/src/editor/utils.

@jodator that was my thought with that, maybe not in proper place, but to keep common logic in editor's code. It was even implemented here:
b80e923#diff-ccd92a4dde1c850ebd60f90f39638203L280
However @Reinmar suggest to duplicate this code in specific editor implementations:
#173 (comment)

It also makes sense to extract this if we ever add another editor type.

AFAIR I talk about this case with @Reinmar and There is very little chance that we introduce new editor type any time soon.

@msamsel msamsel requested a review from jodator June 12, 2019 13:28
Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

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

Fine enough - the place wasn't good. But we can leave those check as they are.

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

Successfully merging this pull request may close these issues.

Confusing behavior of CKEditor 5 when launching the editor on a <textarea> element
5 participants