-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Auto adding #
to color from colordialog
#580
Conversation
@@ -22,6 +22,14 @@ CKEDITOR.dialog.add( 'colordialog', function( editor ) { | |||
html: ' ' |
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.
What is the purpose of the changes in this file?
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.
Change allows on writing unit test for this bug-fix.
Generally writing test for it was very tricky. Problem appeared when ok
button is pressed then method clearHighlight()
is called. What throw an error because unit test doesn't highlight colour in dialog as user does.
So I just add if-statement which check if focus is defined and also rearrange variable declaration to pass JShint.
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.
Color dialog hasn't got any unit test earlier.
This change:
if ( focused ) {
focused.removeClass( focusedColorLightCls );
focused.removeClass( focusedColorDarkCls );
}
Allows on making nice unit test which set up values but doesn't touch focused colour. So test don't throw up errors when only value exists without focusing it.
plugins/colorbutton/plugin.js
Outdated
@@ -203,6 +203,11 @@ CKEDITOR.plugins.add( 'colorbutton', { | |||
total = colors.length + ( moreColorsEnabled ? 2 : 1 ); | |||
|
|||
var clickFn = CKEDITOR.tools.addFunction( function applyColorStyle( color, type ) { | |||
// #565 |
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 add short comment explaining the change.
plugins/colorbutton/plugin.js
Outdated
@@ -203,6 +203,11 @@ CKEDITOR.plugins.add( 'colorbutton', { | |||
total = colors.length + ( moreColorsEnabled ? 2 : 1 ); | |||
|
|||
var clickFn = CKEDITOR.tools.addFunction( function applyColorStyle( color, type ) { | |||
// #565 | |||
if ( /^[0-9a-f]{3}([0-9a-f]{3})?$/i.test( color ) ) { | |||
color = '#' + color; |
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.
IMO the fix is placed in incorrect plugin. I'd move it into colordialog
one, inside onClose
handler of the dialog.
@@ -0,0 +1,240 @@ | |||
/* bender-tags: editor,unit */ |
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.
There's no need for unit
tag.
@@ -0,0 +1,14 @@ | |||
@bender-tags: manual, tc, 4.8.0, feature, 565 |
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.
There's no need for manual
tag.
Ok to sum it up: The fix should land in the There's no question to that, as first of all the enhancement should propagate to all fetarues using Generally speaking it's not This ticket will depend on #590, as AFAICS otherwise we'd have to duplicate this logic in |
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.
The solution works fine. Just a few things to polish in tests.
@@ -0,0 +1,121 @@ | |||
/* bender-tags: editor */ |
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.
Remember to always put unit
tag if it is an unit test.
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.
So we discussed this once again, if unit tag is not needed (not used by bender) it should be skipped.
@@ -0,0 +1,13 @@ | |||
@bender-tags: tc, feature, colordialog, 565, 4.8.0 | |||
@bender-ui: collapsed | |||
@bender-ckeditor-plugins: table,tabletools,colordialog,toolbar,wysiwygarea,sourcearea,contextmenu |
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.
Is sourcearea
plugin really needed here?
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 might be helpful when you wish to check what was included to attribute of tag. E.g. if there will be some invalid string or colour hard to distinguish from others, then checking source might be helpful.
1. Choose background color. | ||
1. Type color in hexadecimal 6-digit format **without** leading `#`. E.g. (`ABC123`). | ||
1. Confirm it. | ||
1. Inseted color should contain additional `#` at the beginning. |
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.
Typo: Inseted -> Inserted
1. Inseted color should contain additional `#` at the beginning. | ||
1. Repeat above steps for color with hexadecimal 3-digits format. E.g. (`FFF`). | ||
|
||
Note: You can also check some wrong situations. |
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 may be not clear what is wrong situation. You could rephrase it like:
You can also check with colors in different formats (rgb, text) or invalid hex strings. For such colors # should not be added.
@@ -0,0 +1,13 @@ | |||
@bender-tags: tc, feature, colordialog, 565, 4.8.0 |
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.
I think we do not use feature
tag (unless it was added recently)?
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.
As it was discussed some time ago there should either bug
or feature
tag? Or does it change since then?
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.
Maybe I'm not up to date - if it was discussed with @mlewand or @Comandeer in the last 2-3 weeks it means it should be that way.
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 was discussed around 12 - 13 June on ckeditor4-chat
. I made some kind of sum up for us as pinned post to ckeditor4-chat.
|
||
bender.editor = {}; | ||
|
||
var test = { |
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.
There is no need to assign it to a variable, you can just write it asbender.test( { ... } )
.
}, | ||
|
||
'test colordialog does not add hash empty value': function() { | ||
var editor = this.editor; |
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.
All tests have very similar body, maybe it could be extracted to a separate function like assertColor( editor, initialColor, expectedColor )
and then each test will be a one liner, e.g. assertColor( this.editor, '123456', '#123456')
.
If you put the function inside test
object you can even omit editor
param because of the same scope so this.editor
will be available there.
wait(); | ||
}, | ||
|
||
'test colordialog does not add hash 1 digit': function() { |
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.
This test fails on IE8.
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.
Just three little details to adjust in the tests and it will be ready :)
wait(); | ||
}, | ||
|
||
'test colordialog add hash to colors 6 digits': function() { |
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.
I think test names would be more readable like:
test colordialog add hash to colors - 6 digits
test colordialog add hash to colors: 6 digits
test colordialog add hash to colors with 6 digits color
}, | ||
|
||
'test colordialog does not add hash 1 digit': function() { | ||
// IE8 don't allow on totally wrong values of attributes |
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.
IE8 doesn't allowing invalid values means the attribute will not be set? I think it might be more clear with something like:
IE8 doesn't allow to use invalid color values.
or IE8 doesn't set invalid color values.
?
|
||
1. Right click into table cell. | ||
1. Select `Cell -> Cell Properties`. | ||
1. Choose background color. |
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.
Does it mean to click Choose
button and then type color in a colordialog
? It might be a little unclear, and typing color without hash in Cell Properties
dialog does not add hash (and color when closing dialog) so it may seem it is broken in this case.
To make it more clear you may use: Click Choose next to Background Color
or something similar.
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.
LGTM!
Tomasz is off, while all the points from the list has been addressed
4de4d20
to
2b6bd45
Compare
What is the purpose of this pull request?
New feature
Does your PR contain necessary tests?
yes
This PR contains
What changes did you make?
There will be automatically added
#
to colour incolordialog
plugin, if colour will be 3 or 6 hexadecimal digit.Closes #607.