-
Notifications
You must be signed in to change notification settings - Fork 12
Fix color for lines on first render in Customizer and dynamically update default color when theme is changed #251
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
Conversation
syntax-highlighting-code-block.php
Outdated
| $highlighted_line_background_color_setting->default = get_default_line_background_color( get_plugin_option( 'theme_name' ) ); // This has no effect. | ||
| // This is the default value used when highlighting lines on first load in Customizer. | ||
| $highlighted_line_background_color_setting->default = get_plugin_option( 'highlighted_line_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.
I can't seem to cause this code to execute as the comment indicates. At least, it runs only in the Customizer preview window not in the customize.php window where the control is. Therefore the change here doesn't seem to make any change. And the return values are the same:
get_default_line_background_color( get_plugin_option( 'theme_name' ) ) ➡️ #ddf6ff
get_plugin_option( 'highlighted_line_background_color' ) ➡️ #ddf6ff
I guess the change here is rather just a refactor since the latter code added is the same as the former code? If so, should the comment change be reverted?
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.
Actually, I can see a reason for going back to get_default_line_background_color( get_plugin_option( 'theme_name' ) ), with some modification. What if someone is using the syntax_highlighting_code_block_style filter? The default style should reflect what that theme is, not what the option is, since we aren't using the option at all, as the filtered value is overriding it. I've tried that in a3078c7.
|
Note that the highlighted line color doesn't dynamically update here upon changing the theme, which is what this
But after publishing changes and reloading then the dracula default highlighted line color shows up:
|
|
Using the latest commit on this PR, I get the following behavior: Where the side panel is correctly picking the correct color but the preview is using another color. I'm just clicking on "Customize" on the admin toolbar from my WP homepage. The Customize preview doesn't get the correct color until I switch the color in the Customize panel. |
|
You're right. I think I've addressed that in 79d66d6 which also ended up cleaning things up quite a bit. |
I'm starting to draft the necessary Customizer JS code to make the default color dynamic. |
|
There we go. Check out 9db5aa6. When no option is yet saved, opening the Customizer shows initially: Upon changing the theme to darcula, the highlighted line color dynamically changes to its respective default: As long as the selected highlight color is the same as the default color, it will continue to change when selecting other themes: Once I've selected a custom color, however, the automatic syncing is stopped: Until I click to set the Default color: And then the synchronization is resumed: |
|
Oh this is awesome! I'm liking this improved behavior and can confirm it works as you specified. Though it does seem like such a workaround for such a small use case but it works 😄 |














The "Highlighted Line Color" is correctly selected in the Customize panel but the color used in the preview at first load is incorrect.
Before
After