Skip to content

Conversation

@allejo
Copy link
Contributor

@allejo allejo commented Dec 28, 2020

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

Before

image

After

image

@allejo allejo requested a review from westonruter December 28, 2020 01:10
@westonruter
Copy link
Owner

I can confirm this works:

Before After
Screen Shot 2020-12-27 at 17 53 35 Screen Shot 2020-12-27 at 17 53 54

Comment on lines 731 to 735
$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' );
Copy link
Owner

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?

Copy link
Owner

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.

@westonruter
Copy link
Owner

This now fixes a condition when you switch from default to dracula where the highlighted line color doesn't change as expected in the preview:

Before After
Screen Shot 2020-12-27 at 21 24 00 Screen Shot 2020-12-27 at 21 24 20

@westonruter
Copy link
Owner

westonruter commented Dec 28, 2020

Note that the highlighted line color doesn't dynamically update here upon changing the theme, which is what this todo is getting at:

* @todo What's missing is dynamically changing the default value of the highlighted_line_background_color control based on the selected theme.

But after publishing changes and reloading then the dracula default highlighted line color shows up:

Before (db88f3d) After (a3078c7)
Screen Shot 2020-12-27 at 21 31 20 Screen Shot 2020-12-27 at 21 31 34

@allejo
Copy link
Contributor Author

allejo commented Dec 28, 2020

Using the latest commit on this PR, I get the following behavior:

image

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.

@westonruter
Copy link
Owner

You're right. I think I've addressed that in 79d66d6 which also ended up cleaning things up quite a bit.

@westonruter
Copy link
Owner

Note that the highlighted line color doesn't dynamically update here upon changing the theme, which is what this todo is getting at

I'm starting to draft the necessary Customizer JS code to make the default color dynamic.

@westonruter
Copy link
Owner

There we go. Check out 9db5aa6.

When no option is yet saved, opening the Customizer shows initially:

image

Upon changing the theme to darcula, the highlighted line color dynamically changes to its respective default:

image

As long as the selected highlight color is the same as the default color, it will continue to change when selecting other themes:

image

Once I've selected a custom color, however, the automatic syncing is stopped:

image

Until I click to set the Default color:

image

image

And then the synchronization is resumed:

image

@westonruter westonruter changed the title Fix color for lines on first render in Customizer Fix color for lines on first render in Customizer and dynamically update default color when theme is changed Dec 28, 2020
@allejo
Copy link
Contributor Author

allejo commented Dec 28, 2020

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 😄

@westonruter westonruter merged commit c90bb70 into develop Dec 29, 2020
@westonruter westonruter deleted the fix/default-highlighted-line-color branch December 29, 2020 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants