-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix Find/Replace unit tests and clean up event handling for animations #5213
Changes from 5 commits
9d8a24e
c0b6510
86dc22c
450642b
74c09c8
60faaec
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 |
---|---|---|
|
@@ -1101,13 +1101,18 @@ define(function (require, exports, module) { | |
self._inlineWidgets.push(inlineWidget); | ||
|
||
// Set up the widget to start closed, then animate open when its initial height is set. | ||
function finishAnimating(e) { | ||
if (e.target === inlineWidget.$htmlContent.get(0)) { | ||
inlineWidget.$htmlContent | ||
.removeClass("animating") | ||
.off("webkitTransitionEnd", finishAnimating); | ||
deferred.resolve(); | ||
} | ||
} | ||
inlineWidget.$htmlContent | ||
.height(0) | ||
.addClass("animating") | ||
.one("webkitTransitionEnd", function () { | ||
inlineWidget.$htmlContent.removeClass("animating"); | ||
deferred.resolve(); | ||
}); | ||
.on("webkitTransitionEnd", finishAnimating); | ||
|
||
// Callback to widget once parented to the editor. The widget should call back to | ||
// setInlineWidgetHeight() in order to set its initial height and animate open. | ||
|
@@ -1134,10 +1139,22 @@ define(function (require, exports, module) { | |
* @return {$.Promise} A promise that is resolved when the inline widget is fully closed and removed from the DOM. | ||
*/ | ||
Editor.prototype.removeInlineWidget = function (inlineWidget) { | ||
var deferred = new $.Deferred(), | ||
self = this; | ||
|
||
function finishAnimating(e) { | ||
if (e.target === inlineWidget.$htmlContent.get(0)) { | ||
inlineWidget.$htmlContent | ||
.removeClass("animating") | ||
.off("webkitTransitionEnd", finishAnimating); | ||
self._codeMirror.removeLineWidget(inlineWidget.info); | ||
self._removeInlineWidgetInternal(inlineWidget); | ||
deferred.resolve(); | ||
} | ||
} | ||
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. For the number of times this pattern of code is repeated (and number of times I imagine that it will be repeated in the future), it seems like it deserves a utility function. Parameters would be:
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. Done. I didn't end up passing all these things in--instead, I just had the utility function return its own promise, and then did the custom processing for each case in the 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. Nice! |
||
|
||
if (!inlineWidget.closePromise) { | ||
var lineNum = this._getInlineWidgetLineNumber(inlineWidget), | ||
deferred = new $.Deferred(), | ||
self = this; | ||
var lineNum = this._getInlineWidgetLineNumber(inlineWidget); | ||
|
||
// Remove the inline widget from our internal list immediately, so | ||
// everyone external to us knows it's essentially already gone. We | ||
|
@@ -1146,12 +1163,7 @@ define(function (require, exports, module) { | |
self._removeInlineWidgetFromList(inlineWidget); | ||
|
||
inlineWidget.$htmlContent.addClass("animating") | ||
.one("webkitTransitionEnd", function () { | ||
inlineWidget.$htmlContent.removeClass("animating"); | ||
self._codeMirror.removeLineWidget(inlineWidget.info); | ||
self._removeInlineWidgetInternal(inlineWidget); | ||
deferred.resolve(); | ||
}) | ||
.on("webkitTransitionEnd", finishAnimating) | ||
.height(0); | ||
|
||
inlineWidget.closePromise = deferred.promise(); | ||
|
@@ -1264,9 +1276,15 @@ define(function (require, exports, module) { | |
} | ||
|
||
function setOuterHeight() { | ||
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. Note that I didn't use |
||
function finishAnimating(e) { | ||
if (e.target === node) { | ||
updateHeight(); | ||
$(node).off("webkitTransitionEnd", finishAnimating); | ||
} | ||
} | ||
$(node).height(height); | ||
if ($(node).hasClass("animating")) { | ||
$(node).one("webkitTransitionEnd", updateHeight); | ||
$(node).on("webkitTransitionEnd", finishAnimating); | ||
} else { | ||
updateHeight(); | ||
} | ||
|
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.
This seems a little cleaner:
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.
Done