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

Improved performance by making the CodeMirror element directly inherit ... #1007

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ define(function (require, exports, module) {


EditorManager.setEditorHolder($('#editor-holder'));
EditorManager.setPositionedEditorHolder($('#positioned-editor-holder'));

// Let the user know Brackets doesn't run in a web browser yet
if (brackets.inBrowser) {
Expand Down
30 changes: 28 additions & 2 deletions src/editor/EditorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ define(function (require, exports, module) {
ViewUtils = require("utils/ViewUtils"),
Strings = require("strings");

/** @type {jQueryObject} DOM node that contains all editors (visible and hidden alike) */
/** @type {jQueryObject} DOM node that we can use to position the _positionedEditorHolder on screen */
var _editorHolder = null;

/** @type {jQueryObject} DOM node that contains all editors (visible and hidden alike) */
var _positionedEditorHolder = null;

/** @type {Editor} */
var _currentEditor = null;
Expand Down Expand Up @@ -230,7 +233,7 @@ define(function (require, exports, module) {
*/
function _createFullEditorForDocument(document) {
// Create editor; make it initially invisible
var container = _editorHolder.get(0);
var container = _positionedEditorHolder.get(0);
var editor = _createEditorForDocument(document, true, container, _openInlineWidget);
editor.setVisible(false);
}
Expand Down Expand Up @@ -304,6 +307,15 @@ define(function (require, exports, module) {
}
}

function _syncEditorPosition() {
if (!_positionedEditorHolder || !_editorHolder)
return;
var offset = _editorHolder.offset();
_positionedEditorHolder.css("left", offset.left)
.css("top", offset.top)
.css("width", _editorHolder.width())
.css("height", _editorHolder.height());
}

/**
* Resize the editor. This should only be called if the contents of the editor holder are changed
Expand All @@ -312,6 +324,7 @@ define(function (require, exports, module) {
* @see #_updateEditorSize()
*/
function resizeEditor() {
_syncEditorPosition();
if (_currentEditor) {
$(_currentEditor.getScrollerElement()).height(_editorHolder.height());
_currentEditor.refresh();
Expand All @@ -324,6 +337,7 @@ define(function (require, exports, module) {
* @see #resizeEditor()
*/
function _updateEditorSize() {
_syncEditorPosition();
// The editor itself will call refresh() when it gets the window resize event.
if (_currentEditor) {
$(_currentEditor.getScrollerElement()).height(_editorHolder.height());
Expand Down Expand Up @@ -447,6 +461,17 @@ define(function (require, exports, module) {
}

_editorHolder = holder;
_editorHolder.css("z-index", "-1000000")
.css("visibility", "hidden");
}

function setPositionedEditorHolder(holder) {
if (_currentEditor) {
throw new Error("Cannot change editor area after an editor has already been created!");
}

_positionedEditorHolder = holder;
_positionedEditorHolder.css("position", "absolute");
}

/**
Expand Down Expand Up @@ -529,6 +554,7 @@ define(function (require, exports, module) {

// Define public API
exports.setEditorHolder = setEditorHolder;
exports.setPositionedEditorHolder = setPositionedEditorHolder;
exports.getCurrentFullEditor = getCurrentFullEditor;
exports.createInlineEditorForDocument = createInlineEditorForDocument;
exports._createFullEditorForDocument = _createFullEditorForDocument;
Expand Down
3 changes: 3 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@

</head>
<body>
<!-- Actual container of CodeMirror editor. -->
<div id="positioned-editor-holder"></div>

<!-- Main UI -->
<div class="main-view">
<div id="sidebar-resizer"></div>
Expand Down
2 changes: 1 addition & 1 deletion src/thirdparty/CodeMirror2