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

Stop using flexbox in editor's parent hierarchy #1847

Merged
merged 5 commits into from
Oct 17, 2012
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions src/editor/EditorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,29 +313,54 @@ define(function (require, exports, module) {
}


/**
* Calculates the available height for the full-size Editor (or the no-editor placeholder),
* accounting for the current size of all visible panels, toolbar, & status bar.
* @return {number}
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

This code implies that all children of editor-holder are containers which are stacked vertically. Currently they are, but someone could add a new element that doesn't play by that rule. At the very least, you should state this in a comment in the main-view.html file. You could also verify this assumption programmatically, but that may impact performance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I'll add a comment in main-view.html.

function _calcEditorHeight() {
var availableHt = $(".content").height();

_editorHolder.siblings().each(function (i, elem) {
var $elem = $(elem);
if ($elem.css("display") !== "none") {
availableHt -= $elem.outerHeight();
}
});
return availableHt;
}

/**
* Resize the editor. This should only be called if the contents of the editor holder are changed
* or if the height of the editor holder changes (except for overall window resizes, which are
* already taken care of automatically).
* @see #_updateEditorSize()
* Resize the editor. This must be called any time the contents of the editor area are swapped
* or any time the editor area might change height. EditorManager takes care of calling this when
* the Editor is swapped, and on window resize. But anyone who changes size/visiblity of editor
* area siblings (toolbar, status bar, bottom panels) *must* manually call resizeEditor().
*
* @param {boolean=} skipRefresh For internal use, to avoid redundant refresh()es during window resize
*/
function resizeEditor() {
function resizeEditor(skipRefresh) {
if (!_editorHolder) {
return; // still too early during init
}

var editorAreaHt = _calcEditorHeight();
_editorHolder.height(editorAreaHt); // affects size of "not-editor" placeholder as well

if (_currentEditor) {
$(_currentEditor.getScrollerElement()).height(_editorHolder.height());
_currentEditor.refresh();
$(_currentEditor.getScrollerElement()).height(editorAreaHt);
if (!skipRefresh) {
_currentEditor.refresh();
}
}
}

/**
* NJ's editor-resizing fix. Whenever the window resizes, we immediately adjust the editor's
* height.
* @see #resizeEditor()
*/
function _updateEditorSize() {
// The editor itself will call refresh() when it gets the window resize event.
if (_currentEditor) {
$(_currentEditor.getScrollerElement()).height(_editorHolder.height());
}
// skipRefresh=true since CodeMirror will call refresh() itself when it sees the resize event
resizeEditor(true);
}

/**
Expand Down
15 changes: 10 additions & 5 deletions src/project/SidebarView.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ define(function (require, exports, module) {
$sidebar.width(width);
$sidebarResizer.css("left", width - 1);

// the following three lines help resize things when the sidebar shows
// but ultimately these should go into ProjectManager.js with a "notify"
// event that we can just call from anywhere instead of hard-coding it.
// waiting on a ProjectManager refactor to add that.
// This maintains the editor position to the right of the sidebar. (A simple float is not enough
// because the non-floated content technically underlaps the floated sidebar; this breaks CodeMirror
// listeners and relative positioning).
// TODO: Ultimately this should go into EditorManager.js, triggered via an event we dispatch
$(".content", $sidebar.parent()).css("margin-left", width);
Copy link
Contributor

Choose a reason for hiding this comment

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

Reminder: Also need to do this in toggleSidebar().

Copy link
Member Author

Choose a reason for hiding this comment

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

My fix for that bug you found is a little different: doing this in the isSidebarClosed case of _setWidth() rather than just the else will fix it without needing to modify toggleSidebar() (since it calls _setWidth()).


// This helps resize things within the sidebar when it's shown.
// TODO: Ultimately this should go into ProjectManager.js, triggered via an event we dispatch
$sidebar.find(".sidebar-selection").width(width);

if (width > 10) {
Expand Down Expand Up @@ -146,6 +150,7 @@ define(function (require, exports, module) {

$sidebarResizer.css("left", sidebarWidth - 1);

// Initially size sidebar at app startup
if (prefs.getValue("sidebarClosed")) {
toggleSidebar(sidebarWidth);
} else {
Expand All @@ -169,7 +174,7 @@ define(function (require, exports, module) {

isMouseDown = true;

// take away the shadows (for performance reasons during sidebarmovement)
// take away the shadows (for performance reasons during sidebar movement)
$sidebar.find(".scroller-shadow").css("display", "none");

$body.toggleClass("resizing");
Expand Down
14 changes: 6 additions & 8 deletions src/styles/brackets.less
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ html, body {
}

body {
.vbox;
height: 100%;

&.resizing a, &.resizing #projects a, &.resizing .main-view, &.resizing .CodeMirror-lines {
cursor: col-resize;
Expand Down Expand Up @@ -88,17 +88,17 @@ a, img {
}

.main-view {
.hbox;
.box-flex(1);
height: 100%;

.sidebar {
height: 100%;
.vbox;
width: @sidebar-width;
float: left;
}

.content {
.vbox;
.box-flex(1);
height: 100%;
}
}

Expand Down Expand Up @@ -222,13 +222,11 @@ a, img {
}

#editor-holder {
.vbox;
.box-flex(1);
position: relative;

/* Placeholder shown when there is no editor open */
#not-editor {
.box-flex(1);
height: 100%;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay! Good riddance flex-box!

Copy link
Member

Choose a reason for hiding this comment

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

Haha, well, if it performed well we would love to use it. Floats and margins make me nauseous.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I totally agree. Maybe one of these days we can donate to webkit the faster implementation Flex used for VBox/HBox ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

In theory, flex-box sounds awesome, but it took very little code to replace it. Yeah, I've been using floats and margins for years and they still seem wrong :) Maybe the sidebar/editor layout could have been implemented using inline-boxes, but we may have run into the same performance problems as with flex-box.

.vbox;
.box-pack(center);
.box-align(center);
Expand Down