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

Commit

Permalink
Merge pull request #888 from cantrell/fontsize
Browse files Browse the repository at this point in the history
Fontsize
  • Loading branch information
njx committed May 18, 2012
2 parents 0fccec9 + 9438517 commit 469c1d0
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 10 deletions.
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
7 changes: 6 additions & 1 deletion 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 Down Expand Up @@ -110,6 +110,11 @@ define(function (require, exports, module) {
key = ele;
}
});

// Check to see if the binding is for "-".
if (key === "" && origDescriptor.search(/^.+--$/) !== -1) {
key = "-";
}

return _buildKeyDescriptor(hasCtrl, hasAlt, hasShift, key);
}
Expand Down
14 changes: 14 additions & 0 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,20 @@ define(function (require, exports, module) {
this._codeMirror.refresh();
};

/**
* Re-renders the editor, and all children inline editors.
*/
Editor.prototype.refreshAll = function () {
this.refresh();
this.getInlineWidgets().forEach(function (multilineEditor, i, arr) {
multilineEditor.sizeInlineWidgetToContents(true);
multilineEditor._updateRelatedContainer();
multilineEditor.editors.forEach(function (editor, j, arr) {
editor.refresh();
});
});
};

/**
* Shows or hides the editor within its parent. Does not force its ancestors to
* become visible.
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 @@ -22,19 +22,83 @@
*/

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

define(function (require, exports, module) {
'use strict';

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 {number} -1 to make the font smaller; 1 to make it bigger.
*/
function _adjustFontSize(direction) {
var styleId = "codemirror-dynamic-fonts";

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

var validFont = /^[\d\.]+(px|em)$/;

// Make sure the font size and line height are expressed in terms
// we can handle (px or em). If not, simply bail.
if (fs.search(validFont) === -1 || lh.search(validFont) === -1) {
return;
}

// Guaranteed to work by the validation above.
var fsUnits = fs.substring(fs.length - 2, fs.length);
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 === -1) {
fsDelta *= -1;
lhDelta *= -1;
}

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

// Don't let the fonts get too small.
if (direction === -1 && ((fsUnits === "px" && fs <= 1) || (fsUnits === "em" && fs <= 0.1))) {
return;
}

// It's necessary to inject a new rule to address all editors.
$("#" + styleId).remove();
var style = $("<style type='text/css'></style>").attr("id", styleId);
style.html(".CodeMirror-scroll {" +
"font-size: " + fsStr + " !important;" +
"line-height: " + lhStr + " !important;}");
$("head").append(style);

EditorManager.getCurrentFullEditor().refreshAll();
}

function _handleIncreaseFontSize() {
_adjustFontSize(1);
}

function _handleDecreaseFontSize() {
_adjustFontSize(-1);
}

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

0 comments on commit 469c1d0

Please sign in to comment.