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

User-configurable whitespace #31

Merged
merged 2 commits into from
Mar 20, 2015
Merged

User-configurable whitespace #31

merged 2 commits into from
Mar 20, 2015

Conversation

le717
Copy link
Collaborator

@le717 le717 commented Jan 14, 2015

For #26. Adds a preference so whitespace can be recolored by the user. Supersedes #30.

Implementation preferences layout

"denniskehrig.ShowWhitespace.colors": {
    "light": {
        "empty": "#ccc",
        "leading": "#ccc",
        "trailing": "#ff0000",
        "whitespace": "#ccc"
    },
    "dark": {
        "empty": "#686963",
        "leading": "#686963",
        "trailing": "#ff0000",
        "whitespace": "#686963"
    }
}

Notes

  • Requires Brackets v0.42 and higher
  • Does not overwrite colors defined by themes. This can be both good and bad.
  • Need good default values for the built-in Brackets dark theme.

var userColors = _preferences.get("colors"),
template = _.template(stylesTemplate),
css = template({
"whitespace": userColors.light.whitespace,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For whatever reason, this one key is not being rendered in both light and dark, but all the others work. I've checked the resulting CSS and it is all valid, so it's odd why it is not working.

@le717
Copy link
Collaborator Author

le717 commented Jan 16, 2015

@DennisKehrig (When you get back,) can you fill me in on why the stylesheet is added/removed to/from the DOM on extension toggle? Was there an historical reason for this or a design choice, and why?

@MiguelCastillo Can you recommend a theme that styles the whitespace this extension creates so I can test if this PR will overwrite that styling?

@MiguelCastillo
Copy link

I don't know a theme that does it as it is generally not common to add classes defined by other extensions. But I can create one for you later this evening.

@le717
Copy link
Collaborator Author

le717 commented Jan 16, 2015

Well what do you know? The Monokai theme styles the whitespace. I can use that for testing.Thanks anyway. :)

@le717
Copy link
Collaborator Author

le717 commented Jan 17, 2015

Miguel, does the whitespace key (.CodeMirror .cm-dk-whitespace-space:before, CodeMirror .cm-dk-whitespace-tab:before) render for you? For whatever reason, that one style in both light and dark does not work, but the others do. Am I doing the Lo-Dash template incorrectly or something? The compiled CSS is correct, but Brackets never renders that one part.

@le717
Copy link
Collaborator Author

le717 commented Jan 17, 2015

What I am talking about can easily been seen in this image:

not-rendered

There should be dots between the variable names and equals signs (as well as equal and value), but clearly, there is not.

@le717
Copy link
Collaborator Author

le717 commented Feb 12, 2015

@MiguelCastillo Except for colors, this is ready to be merged. Could you perhaps do a code review soon, keeping in mind the following points?

  • This is completely unable to override colors defined by the (select few) themes. Is this good or bad?
  • Using two stylesheets is probably not ideal. I could have the colors rendered into main.less then compile the LESS using ExtensionUtils.parseLessCode() and inject it using ExtensionUtils.addEmbeddedStyleSheet(), but this would make any color updates performed by the user follow the same process, and that could be slow. Are there any other ways to merge the stylesheets?

No real rush, though I would like to get this in soon so @DennisKehrig can release whenever he gets back. :)

@le717
Copy link
Collaborator Author

le717 commented Mar 5, 2015

Hey @larz0? I hate to ask you this, but I can't think of anyone else. Would you mind too terribly coming up with some complementary colors for the whitespace that match the built-in Brackets dark theme? There are only two colors: trailing whitespace (which is red in the light theme) and everything else (a light gray in light theme). :)

@MiguelCastillo
Copy link

@le717 OMG! dude I am really sorry, I saw this and somehow completely forgot to get back to you! I will take a look so that we can merge this :)

@le717
Copy link
Collaborator Author

le717 commented Mar 5, 2015

@MiguelCastillo No problem man, I'm terribly busy myself lately. I'm just going back to my open PRs, trying to get them finished up so they don't go stale. :)

@le717
Copy link
Collaborator Author

le717 commented Mar 18, 2015

Miguel, can you please take a look at this really soon? This really needs to be finished up so other pending changes and improvements can be made. :)

@larz0
Copy link

larz0 commented Mar 18, 2015

@le717 sorry I missed this as well somehow. Looks good 👍

@@ -0,0 +1,4 @@
{
"spaceUnits": 4,

Choose a reason for hiding this comment

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

Should this file be checked in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I added this to help keep a basic consistent code style across the files. I'll probably pull it and submit a new PR with it and an equivalent .editorconfig file.

@MiguelCastillo
Copy link

The code looks good. The only real question I have is around the asymmetry when you are registering/unregistering the event handler for themes properties. e.g. PreferencesManager.getExtensionPrefs("themes").on("change", updateColors);

All else looks good to me. :)

@le717
Copy link
Collaborator Author

le717 commented Mar 19, 2015

@larz0 Thanks! :)

@le717
Copy link
Collaborator Author

le717 commented Mar 19, 2015

@MiguelCastillo All feedback addressed, per pending comments. :)

I do have a problem with the listeners, and this is a not a new issue, but it is heightened with the new theme listeners. Despite the presence of the unload() function that tears down and properly closes everything, as far as I can tell that function is never called. I can't seem to log any instance of it or the functions it calls being run when the extension is disabled. Unless it is an implicit run by Brackets and any logs are suppressed, the listeners leak until the program is closed or restarted. Obviously, that is not good. This is not the PR to fix that issue, but it is something I thought I should bring up.

@le717 le717 mentioned this pull request Mar 19, 2015
var CodeMirror = brackets.getModule("thirdparty/CodeMirror2/lib/codemirror");
var _ = brackets.getModule("thirdparty/lodash"),
AppInit = brackets.getModule("utils/AppInit"),
CodeMirror = brackets.getModule("thirdparty/CodeMirror2/lib/codemirror"),

Choose a reason for hiding this comment

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

CodeMirror is an unused variable. I don't know how I missed this one earlier ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Huh. I thought it was still needed after dropping CM2. Removed.

@MiguelCastillo
Copy link

  • This is completely unable to override colors defined by the (select few) themes. Is this good or bad?
    • I think it is good for themes to be able to override colors specified by this extension. The reason is that theme author can style to their heart's content to match the color scheme in the theme.
  • Using two stylesheets is probably not ideal. I could have the colors rendered into main.less then compile the LESS using ExtensionUtils.parseLessCode() and inject it using ExtensionUtils.addEmbeddedStyleSheet(), but this would make any color updates performed by the user follow the same process, and that could be slow. Are there any other ways to merge the stylesheets?
    • I don't really think the performance concern is a big deal because it's not an operation that happens often or repeatedly. I think that having one file is good, either a less or _.template. I would say that _.template would be more performant as the parsing rules are much simpler than less.

function onCheckedStateChange() {
_preferences.set("checked", Boolean(_command.getChecked()));
function onCheckedStateChange(e) {
_preferences.set("checked", e.target._checked);

Choose a reason for hiding this comment

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

This change seems odd... It seems like if there was a regression it would be due to a timing issue where command.getChecked() isn't set when the callback is invoked. Hopefully this will go away when your PR for updating the events is merged.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is what happens when you do late night coding. 😛 Found the real cause and reverted this.

@MiguelCastillo
Copy link

The only concern I have is the regression:

  • function onCheckedStateChange() {
  •    _preferences.set("checked", Boolean(_command.getChecked()));
    
  • function onCheckedStateChange(e) {
  •    _preferences.set("checked", e.target._checked);
    

Otherwise this is ready to be merged.

@MiguelCastillo
Copy link

Yeah man, the changes look great!

compiled = template(_preferences.get("colors"));

// Update the styling with the changes
_styleInline.text(compiled);

Choose a reason for hiding this comment

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

This method is so much tighter! It looks great

@le717
Copy link
Collaborator Author

le717 commented Mar 19, 2015

All review changes and feedback read and addressed. If it still looks good, I'll flatten this and merge it right in!

*/
function _applyColors() {
// Compile the CSS from the template
var template = _.template(stylesTemplate),

Choose a reason for hiding this comment

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

You can create this _.template when the extension loads so that the template does not get parsed each time. This routine will basically become:

 // Update the styling with the changes
_styleInline.text(template(_preferences.get("colors")));

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're catching everything, aren't you? :D

Choose a reason for hiding this comment

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

Of course! I don't like half @ssing things :D

@le717
Copy link
Collaborator Author

le717 commented Mar 19, 2015

I must have not copied my last changes for testing, because with them, I'm getting an whitespace is not defined error, when that key is present (I checked). :\

@le717
Copy link
Collaborator Author

le717 commented Mar 19, 2015

OK, forget that, suddenly it works. The final changes to _applyColors() have been made. I'm going to run this code for this rest of the day to ensure nothing comes up and I'll merge it tonight. If you see anything, let me know, and thank you for taking the time to review this! :)

@MiguelCastillo
Copy link

Sweet, the code looks really clean :) I like it. And you are very welcome! :)

le717 pushed a commit that referenced this pull request Mar 20, 2015
Add user-configurable whitespace colors
@le717 le717 merged commit a9ec742 into master Mar 20, 2015
@le717 le717 deleted the colors-config branch March 20, 2015 00:12
@MiguelCastillo
Copy link

nice work @le717 !

@le717 le717 mentioned this pull request Apr 8, 2015
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.

None yet

3 participants