-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Set the font size before opening the documents #7185
Conversation
* @private | ||
* Sets the font size and restores the scroll position as best as possible. | ||
* @param {string} fontSizeStyle A string with the font size and the size unit | ||
* @param {string} lineHeightStyle A string with the line height and a the size unit |
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.
Old typo: a the size unit
. should remove a
.
This does fix all the reload issues, with or without word wrap on. And I checked with the steps in issue #7168 and is fixed too. The issue that this doesn't fix yet is increasing the font-size with Word Wrap on, but the issue there is in how we restore the scroll position. I need to check later if I can fix that using some of the new CM apis. |
@RaymondLim I fixed the comments and removed the |
var editor = EditorManager.getCurrentFullEditor(), | ||
oldWidth = editor._codeMirror.defaultCharWidth(), | ||
scrollPos = editor.getScrollPos(), | ||
line = editor._codeMirror.lineAtHeight(scrollPos.y, "local"); |
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.
cmv4 is already landed in master and I wonder lineAtHeight
and heightAtLine
are still the same in cmv4. Can you double check or can you merge master to your pull request?
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.
Sure will try, hopefully it should behave the same way.
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 made this PR after cmv4 landed.
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.
Really, but I notice that CM submodule is different.
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.
Yes, I can use multiple cursors in this branch.
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.
Ok.
@RaymondLim Changes pushed. |
lhStr = PreferencesManager.getViewState("lineHeightStyle"); | ||
|
||
if (fsStr && lhStr) { | ||
_removeDynamicFontSize(); |
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 left this remove here, even though we don't need it on the initial load, but it is required if this method is ever called after appReady.
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.
Perfectly fine to call it here to ensure that we don't miss any.
@TomMalbran My changes are pushed. I'm done reviewing your changes and it's your turn to review mine. @dangoor Can you also review my changes in PreferenceStorage.js? |
@RaymondLim The ViewCommands code looks good. I am not that familiar with the new Preferences code to know if your changes are good or not. Edit: nvm the last comment, we only convert from the local storage. |
@TomMalbran Yes, we're migrating only from the local storage. But your point is valid since this pull request is not going to release 37 and we may have a gap in migrating "fontSizeAdjustment" from release 37. Maybe we should stick with "fontSizeAdjustment" and just recalculate font size and line height in your new |
This may or may not be the proper place for this question. But would it be possible to expose the font sizing functionality as an API? I have added the ability to change the font size and type in Themes and it would be really smooth if I could leverage Brackets API instead of Themes completely taking over it. Any thoughts? |
@RaymondLim That can be an option, but we would need to add the default font size as a new constant and remember to change it if we ever change it in the CSS. Anyway we already have that problem with the line height. Another option would be to do a 1 time conversion from the @MiguelCastillo To increase or decrease the font size, you could always call the commands. Or maybe even change the view states. |
@TomMalbran Yeah I saw I could do that. I was looking for a direct way to set a specific font size. |
@MiguelCastillo Wouldn't you just set the font size in the CSS, and have a function to increase it? This code should work for themes with other font-sizes. @RaymondLim I just realized that it will be a bad idea to have the default font-size here, since we would have problems with themes that set the font-size to a different value in the CSS. We can get rid of the line height part by just setting the line height to 1.25 directly in the CSS, and other themes can set it to other unitless-values if required. |
Ok, so here is how themes is working. I have an input field where you can set a particular font size you want to use. There is no button to increase/decrease the size. So, is there a way to tell bracket to set the font size to a specific number/unit? If not, that's no problem. I will just continue to override the style that brackets puts in the document. |
@TomMalbran I like the new view states for saving us from recalculating font size and line height, but I don't like the fact that they are two independent view states. Instead of "fontSizeStyle" and "lineHeightStyle", we should group them just like we have with "linting" preferences. I know that linting preferences have some issues that @dangoor is looking at. @dangoor Can you suggest which solution we should follow? |
@RaymondLim I don't like the way linting was done, since we end up using a Anyway, what about just removing the whole line height part and place it into the CSS? if we just set it to 1.25, then we wouldn't need to update it everytime we update the font-size. @MiguelCastillo No we don't have that function. If |
@TomMalbran Yeap, the dialog to set the specific font size is what I have added in Themes as a configurable setting. So, if brackets provided that then there is no need for that setting in themes. Are the values that are stored by brackets in the preference font sizes or font increments? |
@MiguelCastillo The current stored values are font increments, but this PR will change them to font sizes which include the units, so it would save something like |
@MiguelCastillo Or maybe even easier would be to use |
@TomMalbran we are now thinking the same thing. :) Would you like me to open a PR? |
@MiguelCastillo If you want to. But might be easier to do after we merge this one. |
@TomMalbran I will do a PR. Thanks dude! |
@TomMalbran I like the idea of removing the whole line height part and place it into the CSS. Can you make that change? I'll add the code to do the one-time conversion. |
@RaymondLim Yes, I can do it soon. |
@TomMalbran Actually, can you put the following change in your commit as it also depends on your changes?
|
@RaymondLim I removed the line height and added your code. |
@@ -144,10 +144,8 @@ | |||
*/ | |||
.code-font() { | |||
color: @content-color; | |||
// line-height must be specified in px not em because the code font and line number font sizes are different. | |||
// Sizing via em will cause the code and line numbers to misalign | |||
line-height: 15px; |
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.
This comment is no longer valid, since the line numbers are now in the same div as the rest of the line. Also if we wanted to decrease the font-size value of the line numbers, we can easily increase the line-height value.
@RaymondLim that preference conversion seems fine to me. |
@@ -231,6 +195,30 @@ define(function (require, exports, module) { | |||
} | |||
} | |||
|
|||
/** | |||
* Restores the Font Size and Line Height using the saved strings |
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.
Nit: We can take out Line Height here.
@TomMalbran Done with re-review. ready to merge after you fix the minor nit and the magic number. |
@RaymondLim Fixes pushed |
* @return {Object} JSON object for the new view state equivalent to | ||
* the old "fontSizeAdjustment" preference. | ||
*/ | ||
function _convertToNewViewStates(key, value) { |
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.
Nice job in cleaning. Just one more minor nit since we only have one new view state, can you also rename this to singular _convertToNewViewState
and update the callback argument in convertPreferences
call below?
@RaymondLim done |
Nice job! I really like the changes to new view state. Merging now. |
Set the font size before opening the documents
This is a fix for issue #7093. The idea is to add the styles with the new font-size and line-height before opening any document. To do this, when changing the font-size, we now save the strings that we use to set the styles, so we can use them to set the styles without having any editor open.