ColorPicker: Allow commandStateStore to handle background-color#4034
Conversation
…ction helper" This reverts commit 10b43fa.
|
Here is an example of unexpected behavior that was not possible before fixing this issue, because it wasn't possible to highlight two different sections of a thought using the same color. I recommend that we create a new issue for this. Steps to Reproduce
Expected behaviorEither it adds the background color to the entire thought (ignores caret position within formatted text) or else it removes the formatting tag that immediately surrounds the caret (caret-aware command state) Current behaviorRemoves background color from all selections that have that same color applied Recording.2026-04-07.173429.mp4 |
|
I'm going to add
|
|
This fixes #3905 as well, so I added a test to cover the case of undo restoring previous background colors. |
|
|
||
| it('Can change the background color of a thought that already has the same background color applied to part of its text', async () => { | ||
| const text = | ||
| 'a long enough thought where a tap will fall outside of the <font color="#000000" style="background-color: rgb(255, 87, 61);">formatting</font>' |
There was a problem hiding this comment.
This text is a bit confusing, since the thought is not tapped in this test case, and the length of the thought does not appear to be relevant. Maybe the text was from a different example?
There was a problem hiding this comment.
Simpler:
await paste(`...`)
| it('fully styled thought', () => { | ||
| expect( | ||
| getCommandState( | ||
| '<b><i><u><strike><code><font color="rgb(255, 0, 0)"><span style="background-color: rgb(0, 0, 255)">text</span></font></code></strike></u></i></b>', |
There was a problem hiding this comment.
because it's not possible to create separate tags for foreground and background color using any method that I know.
It is possible to paste valid HTML with separate tags for foreground and background color. Our import logic does not currently have the ability to merge or normalize pasted tags. Also, different platforms may yield different HTML when formatting selected text, so I can't be 100% sure this is safe across iOS and Android. So, it would be best if we could support separate tags.
There was a problem hiding this comment.
I think that if the regex is getting any more complex, then we're better off replacing it with DOMParser. I tried it out on desktop Chrome and iOS Safari and it seems to work the same, and it works OK in the unit tests.
|
It seems I released the new TDD workflow prematurely. Thanks for your patience as I roll out this new part of the CI!
I will look into this. I'm not sure what it means, since
These were supposed to be PR comments, not in-code comments, so that was another big oversight. Test code should never be permanently exempt from TDD. I'll add |
Thanks @karunkop! Did you get it to work locally, or in another branch? I tried my hand at it and ended up with Maybe I'm not doing it right. As for the architecture, I agree that it's not ideal to trigger internal DOM events. The only possible cause that comes to mind is that maybe the event handlers in |
|
Bypassing webdriver is not a good option unfortunately. Webdriver controls a full browser instance, so we should be able to do pretty much anything the user can do. Something else must be preventing this from working as expected. |
I tried updating |
|
@karunkop managed to get the tests passing in a branch, #4249, thanks for that! However, it was accomplished by making tapUp run I created another test branch, #4250, to continue testing. I added logging statements to Any chance that we could revisit these tests at a later time? We could be wrong about something here, but it doesn't seem like webdriverio has functional support for touch events. Possibly this is only the case for web apps. I found webdriverio/webdriverio#7997, which seems to be a related discussion, but not our exact situation. |
|
Sure. If webdriverio has issues with touchevents, that warrants deeper research outside of this PR to figure out how to get proper mobile coverage. Touch events are critical for a lot of functionality. |
This comment was marked as off-topic.
This comment was marked as off-topic.
There was a problem hiding this comment.
Fixed of issues:
- Applying Text Color onto the whole thought text is not responded when a partial of the text already has the same text color #3904
- Undoing text background highlight makes the font invisible when it has a partial text with color #3905
- Issue C: Color is reset to default when trying to apply the same Font Color onto text with Partial Font Color
- Issue D: Color is reset to default when trying to apply the same Font Color onto Note with Partial Font Color
- Issue E: [iOS] Text Color is reset to default when apply any Font Color onto a text with Background Color
- Issue F: [iOS] Note Text Color is reset to default when apply any Font Color onto a text with Background Color
- Issue G: [Desktop] Undoing deletes the whole thought when applying the whole Background Color after applying a partial Background Color
- Issue H: [iOS] Undoing make the text invisible when applying the whole Background Color after applying a partial Background Color
Outstanding issue:
raineorshine
left a comment
There was a problem hiding this comment.
Thank you, nice work
Fixes #3903, #3904 and #3905
It seems that removing the background-color regex fixes this issue pretty effectively. Allowing
commandStateStoreto track the state of formatting at the current caret position means thatselectedwill be true while the caret is inside of a formatting tag, and false while it is outside. This may lead to some unexpected behavior and I will follow up with examples next week, but I feel that this behavior is better addressed incommandStateStoreor possibly in formatSelection rather than through use of this additional regex.I tried to remove the
textHexColorregex as well, but I started to see issues withselectedbeing incorrect, so I figure that we can come back to that if this approach seems to be working.It seemed to work fine in the browser, but the Puppeteer test was showing different behavior until I made a change to the
getCommandStateutil. It was matching on anyfontorspantag within the text that it was analyzing, and I don't think it makes sense to matchforeColororbackColorunless it wraps the entire thought. It is also possible to have the thought wrapped in other formatting tags (<b>,<i>, etc.) so I updated the regex to allow any of those tags at the beginning of the matched text, but to reject any text other than a formatting tag in front of thefontorspan.I did test this against #1957 and #2267 to make sure I wasn't creating any regressions. Let me know if there are other issues associated with this functionality that I should check out.