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

Added backgroundColorSpan support #911

Conversation

felipevaladares
Copy link
Contributor

@felipevaladares felipevaladares commented May 26, 2020

  • Added CssBackgroundColorPlugin based on CssUnderlinePlugin
  • Added AztecBackgroundColorSpan
  • General changes to implement and use BackgroundColorSpan

Test

  1. Run the app
  2. Select some text
  3. Click on the new button that is located between Bold and Quote

Review

@koke @maxme @bummytime @shiki @Tug

device-2020-05-26-184604

@duyvt88
Copy link

duyvt88 commented May 31, 2020

@felipevaladares Hi, can we change the text color of the selected text?
Many thanks!

@felipevaladares
Copy link
Contributor Author

@felipevaladares Hi, can we change the text color of the selected text?
Many thanks!

This is to change the background color, not the text color, but you can use both

@felipevaladares
Copy link
Contributor Author

the idea is to use in cases like the image on this #910

@felipevaladares felipevaladares marked this pull request as draft May 31, 2020 22:45
@felipevaladares felipevaladares marked this pull request as ready for review May 31, 2020 22:46
@duyvt88
Copy link

duyvt88 commented Jun 1, 2020

@felipevaladares Hi, can we change the text color of the selected text?
Many thanks!

This is to change the background color, not the text color, but you can use both

Thanks for your reply. I'm trying to customize your code to change the text color.

@felipevaladares
Copy link
Contributor Author

@felipevaladares Hi, can we change the text color of the selected text?
Many thanks!

This is to change the background color, not the text color, but you can use both

Thanks for your reply. I'm trying to customize your code to change the text color.

I'm not sure if you will be able to do that using my code, you should probably create a new Span and Plugin based on my changes, i believe it will be very similar

@duyvt88
Copy link

duyvt88 commented Jun 6, 2020

@felipevaladares Hi, can we change the text color of the selected text?
Many thanks!

This is to change the background color, not the text color, but you can use both

Thanks for your reply. I'm trying to customize your code to change the text color.

I'm not sure if you will be able to do that using my code, you should probably create a new Span and Plugin based on my changes, i believe it will be very similar

I have done it. Thanks for your support.
image

Do you think we can change the font size of the selected text?
Thanks,

@felipevaladares
Copy link
Contributor Author

@felipevaladares Hi, can we change the text color of the selected text?
Many thanks!

This is to change the background color, not the text color, but you can use both

Thanks for your reply. I'm trying to customize your code to change the text color.

I'm not sure if you will be able to do that using my code, you should probably create a new Span and Plugin based on my changes, i believe it will be very similar

I have done it. Thanks for your support.
image

Do you think we can change the font size of the selected text?
Thanks,

Nice, i'm curious to see your code, have you opened a PR?

@felipevaladares
Copy link
Contributor Author

@koke @maxme @bummytime @shiki @Tug could you guys please review this PR?

@cameronvoell cameronvoell self-requested a review June 8, 2020 18:15
Copy link
Contributor

@cameronvoell cameronvoell left a comment

Choose a reason for hiding this comment

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

Nice work here @felipevaladares. Changes seem on the whole consistent with the existing code base, so nice job with that. However, I did notice a few minor issues that would be good to fix before merging this in.

  1. While testing your PR, I noticed an existing issue that becomes more noticeable with your changes: Format text then remove format removes color style #914 . If you toggle text with background color bold or italic etc., and then toggle back off, the background color disappears unexpectedly. Ideally this is fixed before merging.

  2. In the past we had other issues where certain text patterns did not show a visual for highlighting, or show a cursor when it is placed in the text. I think we are seeing similar issues with text with a backgroundColorSpan, highlighting shows no color change, and the cursor is not visible. Perhaps previous fixes for these types of issues will provide hints on how to fix that. (Issue/219 code highlight color #244 , Fixin visibility of cursor in quote #249)

  3. Perhaps for at least this first iteration we can add Background Color button to the Plugin buttons section of the toolbar, so that it is easy to not include the button if we do not add the new CssBackgroundColorPlugin. This way existing apps using Aztec will not have the new button show up unless they want to use it. (For example, notice if you comment this line

    .addPlugin(MoreToolbarButton(visualEditor))
    the More Button will disappear from the toolbar, but this is not the case if we remove your aztec.addPlugin(CssBackgroundColorPlugin()) because it is in the main layout sections of simple and advanced toolbars instead of the plugin section.)

Thanks again for the changes here.

@felipevaladares
Copy link
Contributor Author

Nice work here @felipevaladares. Changes seem on the whole consistent with the existing code base, so nice job with that. However, I did notice a few minor issues that would be good to fix before merging this in.

1. While testing your PR, I noticed an existing issue that becomes more noticeable with your changes: #914 . If you toggle text with background color bold or italic etc., and then toggle back off, the background color disappears unexpectedly. Ideally this is fixed before merging.

2. In the past we had other issues where certain text patterns did not show a visual for highlighting, or show a cursor when it is placed in the text. I think we are seeing similar issues with text with a backgroundColorSpan, highlighting shows no color change, and the cursor is not visible. Perhaps previous fixes for these types of issues will provide hints on how to fix that. (#244 , #249)

3. Perhaps for at least this first iteration we can add Background Color button to the Plugin buttons section of the toolbar, so that it is easy to not include the button if we do not add the new CssBackgroundColorPlugin. This way existing apps using Aztec will not have the new button show up unless they want to use it. (For example, notice if you comment this line https://github.com/wordpress-mobile/AztecEditor-Android/blob/a1386beed8d8215fe8ab79c501c1ec237ae8a785/app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt#L443
    the More Button will disappear from the toolbar, but this is not the case if we remove your `aztec.addPlugin(CssBackgroundColorPlugin())` because it is in the main layout sections of simple and advanced toolbars instead of the plugin section.)

Thanks again for the changes here.

Hi @cameronvoell thanks for reviewing, i'll try to handle all the issues and improvements as soon as possible :)

@duyvt88
Copy link

duyvt88 commented Jun 18, 2020

@felipevaladares Hi, can we change the text color of the selected text?
Many thanks!

This is to change the background color, not the text color, but you can use both

Thanks for your reply. I'm trying to customize your code to change the text color.

I'm not sure if you will be able to do that using my code, you should probably create a new Span and Plugin based on my changes, i believe it will be very similar

I have done it. Thanks for your support.
image
Do you think we can change the font size of the selected text?
Thanks,

Nice, i'm curious to see your code, have you opened a PR?

Hi @felipevaladares,
Sorry for replying late. Please check my code here https://github.com/duyvt88/AztecEditorCustom.

Thank you very much!

@arctouch-felipevaladares

Nice work here @felipevaladares. Changes seem on the whole consistent with the existing code base, so nice job with that. However, I did notice a few minor issues that would be good to fix before merging this in.

1. While testing your PR, I noticed an existing issue that becomes more noticeable with your changes: #914 . If you toggle text with background color bold or italic etc., and then toggle back off, the background color disappears unexpectedly. Ideally this is fixed before merging.

2. In the past we had other issues where certain text patterns did not show a visual for highlighting, or show a cursor when it is placed in the text. I think we are seeing similar issues with text with a backgroundColorSpan, highlighting shows no color change, and the cursor is not visible. Perhaps previous fixes for these types of issues will provide hints on how to fix that. (#244 , #249)

3. Perhaps for at least this first iteration we can add Background Color button to the Plugin buttons section of the toolbar, so that it is easy to not include the button if we do not add the new CssBackgroundColorPlugin. This way existing apps using Aztec will not have the new button show up unless they want to use it. (For example, notice if you comment this line https://github.com/wordpress-mobile/AztecEditor-Android/blob/a1386beed8d8215fe8ab79c501c1ec237ae8a785/app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt#L443
    the More Button will disappear from the toolbar, but this is not the case if we remove your `aztec.addPlugin(CssBackgroundColorPlugin())` because it is in the main layout sections of simple and advanced toolbars instead of the plugin section.)

Thanks again for the changes here.

@cameronvoell can you verify if the 1st and 3th items are ok? I believe i fixed the #914 also i removed the button from the toolbar and changed to be a plugin, still trying to figure out the second item(highlighting problem)

@arctouch-felipevaladares

@cameronvoell highlight problem fixed 👍

@@ -238,13 +262,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
joinStyleSpans(start, end)
}

fun removeInlineCssStyle(start: Int = selectionStart, end: Int = selectionEnd) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a little suspicious that removing this code might have side effects, though I'm not sure what they are yet. Also this does not seem to fix all cases of #914. For example, if you highlight the first red italic text in the sample text and turn off italic, and then open html you will see the color attribute is gone, and returning from html the color will be gone in the display text.

I did see that background color no longer disappears when you remove a text format so that is an improvement. Perhaps we leave this code as it was since it does not affect background, and it does not seem to completely fix #914 either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is weird, it just remove everything without any rules, not sure if it will break something, maybe it's a work around to something? it really doesn't make any sense to me

@@ -221,8 +247,6 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle) : AztecFormat
editableText.removeSpan(it)
}
}
// remove the CSS style span
removeInlineCssStyle()
Copy link
Contributor

@cameronvoell cameronvoell Jul 31, 2020

Choose a reason for hiding this comment

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

Suggest we keep this for now since it does not affect background color, see previous https://github.com/wordpress-mobile/AztecEditor-Android/pull/911/files#r463370943

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, if really doesn't affect bg color i think we can keep, but its something to take a look in the future, that method doesn't make much sense


class AztecBackgroundColorSpan(
val color: Int,
val alpha: Int = 220,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think only color is ever used as a constructor parameter from here. The other parameters can probably be moved to be class properties. What do you think?

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 problem, i'll take a look into this

@cameronvoell
Copy link
Contributor

cameronvoell commented Jul 31, 2020

Hello @arctouch-felipevaladares , thanks for the updates, and sorry for the delay with the review.

@cameronvoell highlight problem fixed 👍

Nice fix here.

@cameronvoell can you verify if the 1st and 3th items are ok? I believe i fixed the #914 also i removed the button from the toolbar and changed to be a plugin

I left some comments about the 1st item, along with a few other comments on the code. The 3rd item for making the background button functionality an optional plugin is looking good as well 👍

I did find one other issue that is related to the highlight state of the Background button. It looks like after highlighting some text and then navigating elsewhere the button stays highlighted. The button should function like the other buttons in that it is highlighted only when placed above or highlighting text that has that property, and then it should automatically go to inactive state when moved elsewhere (see bold or italic button for example).

@maxme
Copy link
Contributor

maxme commented Aug 3, 2020

Just a note that we're changing the project license, since this haven't landed yet it's not a problem, but if the patch land after the switch, it will be done under the MPL v2.

Ref. #922

@yuvalgnessin-qz
Copy link
Contributor

Hi @felipevaladares :) do you think you might be able to respond to @cameronvoell's comments in the near term? If not, I might be interested in taking over this effort. Let me know!

@felipevaladares
Copy link
Contributor Author

Hi @felipevaladares :) do you think you might be able to respond to @cameronvoell's comments in the near term? If not, I might be interested in taking over this effort. Let me know!

Hi @yuvalgnessin-qz i will do that this week :)

@felipevaladares
Copy link
Contributor Author

Just a note that we're changing the project license, since this haven't landed yet it's not a problem, but if the patch land after the switch, it will be done under the MPL v2.

Ref. #922

No problem, i agree

@starshipcoder
Copy link
Contributor

I suggest the background icon take the current background color, so moving cursor could modify this color too

And it will be ready for a color picker

@yuvalgnessin-qz
Copy link
Contributor

Hello @cameronvoell and others! Since @felipevaladares was not available to address the changes you requested, I have opened a new PR #934 implemented by @lvcasasanta to replace this one. It addresses all the changes you have requested.

Please take a look as soon as you can. Thank you!

@SiobhyB
Copy link

SiobhyB commented Apr 6, 2023

I'm going ahead to close this PR, as it's been superseded by #1041.

@SiobhyB SiobhyB closed this Apr 6, 2023
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.

8 participants