Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fontsize #888

Merged
merged 11 commits into from
May 18, 2012
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ define(function (require, exports, module) {

// VIEW
{"Ctrl-Shift-H": Commands.VIEW_HIDE_SIDEBAR},
{"Ctrl-=": Commands.VIEW_INCREASE_FONT_SIZE},
{"Ctrl--": Commands.VIEW_DECREASE_FONT_SIZE},

// Navigate
{"Ctrl-Shift-O": Commands.NAVIGATE_QUICK_OPEN},
Expand Down
4 changes: 3 additions & 1 deletion src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ define(function (require, exports, module) {
exports.EDIT_LINE_COMMENT = "edit.lineComment";

// VIEW
exports.VIEW_HIDE_SIDEBAR = "view.hideSidebar";
exports.VIEW_HIDE_SIDEBAR = "view.hideSidebar";
exports.VIEW_INCREASE_FONT_SIZE = "view.increaseFontSize";
exports.VIEW_DECREASE_FONT_SIZE = "view.decreaseFontSize";

// Navigate
exports.NAVIGATE_QUICK_OPEN = "navigate.quickOpen";
Expand Down
15 changes: 10 additions & 5 deletions src/command/KeyMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp:true */
/*global define, brackets */

define(function (require, exports, module) {
Expand All @@ -35,12 +35,17 @@ define(function (require, exports, module) {
* @param {boolean} hasAlt Is Alt key enabled
* @param {boolean} hasShift Is Shift key enabled
* @param {string} key The key that's pressed
* @param {string} origDescriptor The optional original descriptor
* @return {string} The normalized key descriptor
*/
function _buildKeyDescriptor(hasCtrl, hasAlt, hasShift, key) {
function _buildKeyDescriptor(hasCtrl, hasAlt, hasShift, key, origDescriptor) {
if (!key) {
console.log("KeyMap _buildKeyDescriptor() - No key provided!");
return "";
if (origDescriptor && origDescriptor.search(/^.+--$/) !== -1) { // Check if the binding is for "-"
key = "-";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this logic would be better in _normalizeKeyDescriptorString(), since that's actually where the logical loophole is that causes the problem--i.e., it should be treated as a workaround for the fact that we're splitting on "-", and we should explicitly test for the case there.

} else {
console.log("KeyMap _buildKeyDescriptor() - No key provided!");
return "";
}
}

var keyDescriptor = [];
Expand Down Expand Up @@ -111,7 +116,7 @@ define(function (require, exports, module) {
}
});

return _buildKeyDescriptor(hasCtrl, hasAlt, hasShift, key);
return _buildKeyDescriptor(hasCtrl, hasAlt, hasShift, key, origDescriptor);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/styles/brackets_codemirror_override.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@

/* Brackets / CodeMirror Code Formatting */

/*
* TODO This can be removed next time we update CodeMirror2.
* Marijn made this change to codemirror.css, but I need it now
* in order to make font resizing work.
*/
.CodeMirror pre {
line-height: inherit;
}

.CodeMirror-scroll {
background-color: @background-color-3;
}
Expand Down
8 changes: 3 additions & 5 deletions src/styles/brackets_theme_default.less
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@
*/
.code-font() {
color: @content-color;
pre {
// 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;
}
// 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;
}

.code-font-win() {
Expand Down
70 changes: 67 additions & 3 deletions src/view/ViewCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*jslint vars: true, plusplus: true, devel: true, browser: true, nomen: true, indent: 4, maxerr: 50 */
Copy link
Member

Choose a reason for hiding this comment

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

we prefer to explicitly call out 'window' instead of 'browser'

/*global define, $ */

define(function (require, exports, module) {
Expand All @@ -30,11 +30,75 @@ define(function (require, exports, module) {
var Commands = require("command/Commands"),
CommandManager = require("command/CommandManager"),
SidebarView = require("project/SidebarView"),
ProjectManager = require("project/ProjectManager");
ProjectManager = require("project/ProjectManager"),
EditorManager = require("editor/EditorManager");

function _handleHideSidebar() {
SidebarView.toggleSidebar();
}

CommandManager.register(Commands.VIEW_HIDE_SIDEBAR, _handleHideSidebar);
/**
* @private
* Increases or decreases the editor's font size.
* @param {string} "up" or "down"
*/
function _adjustFontSize(direction) {
var styleId = "codemirror-dynamic-fonts";

var fs = $(".CodeMirror-scroll").css("font-size");
var lh = $(".CodeMirror-scroll").css("line-height");

var fsUnits = fs.substring(fs.length - 2, fs.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to guard against fs or lh having length < 2?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, although we don't set other font size types like percentages, it's conceivable (though probably unlikely) that someone might set that in a theme. We might want to detect those cases and just bail rather than doing something nonsensical. (i.e., explicitly test that the last two characters are either "em" or "px", and if neither, then bail.)

var lhUnits = lh.substring(lh.length - 2, lh.length);

fs = fs.substring(0, fs.length - 2);
lh = lh.substring(0, lh.length - 2);

var fsDelta = (fsUnits === "px") ? 1 : 0.1;
var lhDelta = (lhUnits === "px") ? 1 : 0.1;

if (direction === "down") {
fsDelta *= -1;
lhDelta *= -1;
}

var fsStr = (parseFloat(fs) + fsDelta) + fsUnits;
var lhStr = (parseFloat(lh) + lhDelta) + lhUnits;

if (fsStr === "1px" || fsStr === ".1em") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we check the numeric values instead, and use <=? It's conceivable someone might set a font size like 1.25em.

return;
}

$("#" + styleId).remove();
var style = window.document.createElement("style");
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're using jQuery anyway, seems nicer to just do $("<style type='text/css'></style>").attr("id", styleId) or some such.

style.setAttribute("type", "text/css");
style.setAttribute("id", styleId);
style.innerHTML = ".CodeMirror-scroll{font-size:" + fsStr +
" !important;line-height:" + lhStr + " !important;}";
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't seem necessary to skimp on whitespace in this string--might as well make it more legible.

$("head").append(style);

var fullEditor = EditorManager.getCurrentFullEditor();
Copy link
Contributor

Choose a reason for hiding this comment

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

The following code (to the end of the function) feels like it knows too much about the guts of editors and inline editors. Could we add a new method on Editor with this code in it, called something like refreshAll(), and just call that from here?

fullEditor._codeMirror.refresh();

var inlineEditors = fullEditor.getInlineWidgets();
inlineEditors.forEach(function (multilineEditor, i, arr) {
multilineEditor.sizeInlineWidgetToContents(true);
multilineEditor._updateRelatedContainer();
multilineEditor.editors.forEach(function (editor, j, arr) {
editor._codeMirror.refresh();
});
});
}

function _handleIncreaseFontSize() {
_adjustFontSize("up");
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit: could we just pass 1 or -1?

}

function _handleDecreaseFontSize() {
_adjustFontSize("down");
}

CommandManager.register(Commands.VIEW_HIDE_SIDEBAR, _handleHideSidebar);
CommandManager.register(Commands.VIEW_INCREASE_FONT_SIZE, _handleIncreaseFontSize);
CommandManager.register(Commands.VIEW_DECREASE_FONT_SIZE, _handleDecreaseFontSize);
});