-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix for issue #1122 #1661
Fix for issue #1122 #1661
Changes from 8 commits
164ffa8
3b05f42
19fa897
22855c0
e714f38
cbadfc4
e2ff4ea
9e25576
e853066
ea3354c
6a933a3
5559cd3
c561ef0
2044846
8f1cfb2
aab262d
ab2645a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
|
||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ | ||
/*global define, $, brackets, JSLINT, PathUtils */ | ||
/*global define, $, JSLINT, PathUtils, document, window */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like both document and window are no longer used and can be removed |
||
|
||
/** | ||
* Allows JSLint to run on the current document and report results in a UI panel. | ||
|
@@ -44,8 +44,22 @@ define(function (require, exports, module) { | |
EditorManager = require("editor/EditorManager"), | ||
PreferencesManager = require("preferences/PreferencesManager"), | ||
PerfUtils = require("utils/PerfUtils"), | ||
Strings = require("strings"); | ||
Strings = require("strings"), | ||
AppInit = require("utils/AppInit"); | ||
|
||
var MIN_HEIGHT = 100; | ||
|
||
var PREFERENCES_CLIENT_ID = module.id, | ||
defaultPrefs = { height: 200, enabled: true }; | ||
|
||
// These vars are initialized by the htmlReady handler | ||
// below since they refer to DOM elements | ||
var $mainView, | ||
$jslintResults, | ||
$jslintContent, | ||
$jslintToolbar, | ||
$jslintResizer; | ||
|
||
/** | ||
* @private | ||
* @type {PreferenceStorage} | ||
|
@@ -200,14 +214,101 @@ define(function (require, exports, module) { | |
setEnabled(!getEnabled()); | ||
} | ||
|
||
/** | ||
* @private | ||
* Sets jslint panel height and resizes editor. | ||
* @param {number} height Height in pixels. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of duplicated code here that needs to be refactored into a single resizer class. There are several other extensions (and I expect more to come) that also use the bottom panel adn would like to have this same functionality: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't thought about the other extensions... should we refactor this in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
function _setHeight(height) { | ||
// There seems to be a race condition when accessing height if JSLint is | ||
// enabled when Brackets is opening. Neither htmlReady nor appReady seem | ||
// to work for that. Forcing 27px height for the toolbar in that case. | ||
var toolbarHeight = $jslintToolbar.outerHeight(true); | ||
if (!$jslintToolbar.height()) { | ||
toolbarHeight = 27; | ||
} | ||
|
||
height = Math.max(height, MIN_HEIGHT); | ||
_prefs.setValue("height", height); | ||
|
||
$jslintResults.height(height); | ||
$jslintContent.height(height - toolbarHeight); | ||
|
||
EditorManager.resizeEditor(); | ||
} | ||
|
||
/** | ||
* @private | ||
* Initialize resize handling. | ||
*/ | ||
function _initJSLintResizer() { | ||
var $body = $(document.body), | ||
animationRequest = null, | ||
isMouseDown = false; | ||
|
||
if (_enabled) { | ||
_setHeight(_prefs.getValue("height")); | ||
} | ||
|
||
$jslintResizer.on("mousedown.jslint", function (e) { | ||
var startY = e.clientY, | ||
startHeight = $jslintResults.height(), | ||
newHeight = startHeight + (startY - e.clientY), | ||
doResize = true; | ||
|
||
isMouseDown = true; | ||
$body.toggleClass("hor-resizing"); | ||
|
||
animationRequest = window.webkitRequestAnimationFrame(function doRedraw() { | ||
// only run this if the mouse is down so we don't constantly loop even | ||
// after we're done resizing. | ||
if (!isMouseDown) { | ||
return; | ||
} | ||
|
||
if (doResize) { | ||
_setHeight(newHeight); | ||
} | ||
|
||
animationRequest = window.webkitRequestAnimationFrame(doRedraw); | ||
}); | ||
|
||
$mainView.on("mousemove.jslint", function (e) { | ||
// calculate newHeight as difference between stargint and current | ||
// position to avoid dependencies with other panels | ||
newHeight = startHeight + (startY - e.clientY); | ||
e.preventDefault(); | ||
}); | ||
|
||
$mainView.one("mouseup.jslint", function (e) { | ||
isMouseDown = false; | ||
$mainView.off("mousemove.jslint"); | ||
$body.toggleClass("hor-resizing"); | ||
}); | ||
|
||
e.preventDefault(); | ||
}); | ||
} | ||
|
||
// Register command handlers | ||
CommandManager.register(Strings.CMD_JSLINT, Commands.TOGGLE_JSLINT, _handleToggleJSLint); | ||
|
||
// Init PreferenceStorage | ||
_prefs = PreferencesManager.getPreferenceStorage(module.id, { enabled: !!brackets.config.enable_jslint }); | ||
_prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs); | ||
_setEnabled(_prefs.getValue("enabled")); | ||
|
||
// Initialize items dependent on HTML DOM | ||
AppInit.htmlReady(function () { | ||
$mainView = $(".main-view"); | ||
$jslintResults = $("#jslint-results"); | ||
$jslintResizer = $("#jslint-resizer"); | ||
$jslintToolbar = $("#jslint-results .toolbar"); | ||
$jslintContent = $("#jslint-results .table-container"); | ||
|
||
// init | ||
_initJSLintResizer(); | ||
}); | ||
|
||
// Define public API | ||
exports.run = run; | ||
exports.getEnabled = getEnabled; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
*/ | ||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ | ||
/*global define, $, PathUtils, window */ | ||
/*global define, $, PathUtils, window, document */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like both document and window are no longer used and can be removed |
||
|
||
/* | ||
* Adds a "find in files" command to allow the user to find all occurances of a string in all files in | ||
|
@@ -50,11 +50,25 @@ define(function (require, exports, module) { | |
DocumentManager = require("document/DocumentManager"), | ||
EditorManager = require("editor/EditorManager"), | ||
FileIndexManager = require("project/FileIndexManager"), | ||
AppInit = require("utils/AppInit"), | ||
PreferencesManager = require("preferences/PreferencesManager"), | ||
KeyEvent = require("utils/KeyEvent"); | ||
|
||
|
||
var FIND_IN_FILES_MAX = 100; | ||
|
||
var MIN_HEIGHT = 100; | ||
|
||
var PREFERENCES_CLIENT_ID = module.id, | ||
defaultPrefs = { height: 200 }; | ||
|
||
// These vars are initialized by the htmlReady handler | ||
// below since they refer to DOM elements | ||
var $mainView, | ||
$searchResults, | ||
$searchContent, | ||
$searchToolbar, | ||
$searchResizer; | ||
|
||
// This dialog class was mostly copied from QuickOpen. We should have a common dialog | ||
// class that everyone can use. | ||
|
||
|
@@ -332,6 +346,85 @@ define(function (require, exports, module) { | |
} | ||
}); | ||
} | ||
|
||
/** | ||
* @private | ||
* Sets jslint panel height and resizes editor. | ||
* @param {number} height Height in pixels. | ||
*/ | ||
function _setHeight(height) { | ||
var prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs); | ||
|
||
height = Math.max(height, MIN_HEIGHT); | ||
|
||
$searchResults.height(height); | ||
$searchContent.height(height - $searchToolbar.outerHeight()); | ||
|
||
prefs.setValue("height", height); | ||
EditorManager.resizeEditor(); | ||
} | ||
|
||
/** | ||
* @private | ||
* Install resize handling. | ||
*/ | ||
function _initSearchResizer() { | ||
var $body = $(document.body), | ||
prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs), | ||
animationRequest = null, | ||
isMouseDown = false; | ||
|
||
$searchResizer.on("mousedown.search", function (e) { | ||
var startY = e.clientY, | ||
startHeight = $searchResults.height(), | ||
newHeight = startHeight + (startY - e.clientY), | ||
doResize = true; | ||
|
||
isMouseDown = true; | ||
$body.toggleClass("hor-resizing"); | ||
|
||
animationRequest = window.webkitRequestAnimationFrame(function doRedraw() { | ||
// only run this if the mouse is down so we don't constantly loop even | ||
// after we're done resizing. | ||
if (!isMouseDown) { | ||
return; | ||
} | ||
|
||
if (doResize) { | ||
_setHeight(newHeight); | ||
} | ||
|
||
animationRequest = window.webkitRequestAnimationFrame(doRedraw); | ||
}); | ||
|
||
$mainView.on("mousemove.search", function (e) { | ||
// calculate newHeight as difference between stargint and current | ||
// position to avoid dependencies with other panels | ||
newHeight = startHeight + (startY - e.clientY); | ||
e.preventDefault(); | ||
}); | ||
|
||
$mainView.one("mouseup.search", function (e) { | ||
isMouseDown = false; | ||
$mainView.off("mousemove.search"); | ||
$body.toggleClass("hor-resizing"); | ||
}); | ||
|
||
e.preventDefault(); | ||
}); | ||
} | ||
|
||
CommandManager.register(Strings.CMD_FIND_IN_FILES, Commands.EDIT_FIND_IN_FILES, doFindInFiles); | ||
}); | ||
|
||
// Initialize items dependent on HTML DOM | ||
AppInit.htmlReady(function () { | ||
$mainView = $(".main-view"); | ||
$searchResults = $("#search-results"); | ||
$searchResizer = $("#search-resizer"); | ||
$searchToolbar = $("#search-results .toolbar"); | ||
$searchContent = $("#search-results .table-container"); | ||
|
||
// init | ||
_initSearchResizer(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,12 @@ body { | |
&.resizing a, &.resizing #projects a, &.resizing .main-view, &.resizing .CodeMirror-lines { | ||
cursor: col-resize; | ||
} | ||
|
||
/* This appears to be necessary in Firefox when body is set to display: box. */ | ||
height: 100%; | ||
&.hor-resizing a, &.hor-resizing #projects a, &.hor-resizing .main-view, &.hor-resizing .CodeMirror-lines { | ||
cursor: row-resize; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brackets currently doesn't support Firefox, so is this necessary? Maybe the comment is incorrect. |
||
} | ||
|
||
|
||
|
@@ -116,6 +122,15 @@ a, img { | |
border-width: 1px; | ||
border-color: lighten(@bc-grey, @bc-color-step-size*4); | ||
|
||
.h-resizer { | ||
position: absolute; | ||
height: 6px; | ||
width: 100%; | ||
z-index: @z-index-brackets-bottom-resizer; | ||
opacity: 0; | ||
cursor: row-resize; | ||
} | ||
|
||
.toolbar { | ||
height: auto; | ||
padding-top: @base-padding / 2; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,5 +50,6 @@ | |
|
||
@z-index-brackets-sidebar-resizer: @z-index-brackets-ui + 2; | ||
@z-index-brackets-resizer-div: @z-index-brackets-sidebar-resizer + 1; | ||
@z-index-brackets-bottom-resizer: @z-index-brackets-ui + 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @z-index-brackets-bottm-panel-resizer would be more accurate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will fix... |
||
|
||
@z-index-brackets-context-menu-base: 1000; |
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.
Would be nice if the resizing functionality could be added to a bottom panel simply by adding a the h-resizer class to the parent container and this DIV was dynamically added to the DOM. This would make it easier and less obtrusive to add.
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.
Would it be okay to have a module like
utils/Resizer
and scan for resizer classes on initialization to add the necessary elements as well as configure the behavior?It could work also on the sidebar...
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, that sounds like the best solution.