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

Commit c494e93

Browse files
committed
Merge pull request #5899 from adobe/nj/issue-5643
Fix issues with updating inline editor when not visible
2 parents 6ca6512 + fc38985 commit c494e93

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

src/editor/Editor.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,12 @@ define(function (require, exports, module) {
11371137
var deferred = new $.Deferred(),
11381138
self = this;
11391139

1140+
function finishRemoving() {
1141+
self._codeMirror.removeLineWidget(inlineWidget.info);
1142+
self._removeInlineWidgetInternal(inlineWidget);
1143+
deferred.resolve();
1144+
}
1145+
11401146
if (!inlineWidget.closePromise) {
11411147
var lineNum = this._getInlineWidgetLineNumber(inlineWidget);
11421148

@@ -1146,13 +1152,17 @@ define(function (require, exports, module) {
11461152
// the other stuff in _removeInlineWidgetInternal to wait until then).
11471153
self._removeInlineWidgetFromList(inlineWidget);
11481154

1149-
AnimationUtils.animateUsingClass(inlineWidget.htmlContent, "animating")
1150-
.done(function () {
1151-
self._codeMirror.removeLineWidget(inlineWidget.info);
1152-
self._removeInlineWidgetInternal(inlineWidget);
1153-
deferred.resolve();
1154-
});
1155-
inlineWidget.$htmlContent.height(0);
1155+
// If we're not visible (in which case the widget will have 0 client height),
1156+
// don't try to do the animation, because nothing will happen and we won't get
1157+
// called back right away. (The animation would happen later when we switch
1158+
// back to the editor.)
1159+
if (self.isFullyVisible()) {
1160+
AnimationUtils.animateUsingClass(inlineWidget.htmlContent, "animating")
1161+
.done(finishRemoving);
1162+
inlineWidget.$htmlContent.height(0);
1163+
} else {
1164+
finishRemoving();
1165+
}
11561166
inlineWidget.closePromise = deferred.promise();
11571167
}
11581168
return inlineWidget.closePromise;

src/editor/MultiRangeInlineEditor.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,8 @@ define(function (require, exports, module) {
239239
// compute scrollbars
240240
this.$relatedContainer.height(this.$related.height());
241241

242-
// Update the position of the selected marker now that we're laid out, and then
243-
// set it to animate for future updates.
244-
this._updateSelectedMarker().done(function () {
245-
self.$selectedMarker.addClass("animate");
246-
});
242+
// Set the initial position of the selected marker now that we're laid out.
243+
this._updateSelectedMarker(false);
247244

248245
// Call super
249246
MultiRangeInlineEditor.prototype.parentClass.onAdded.apply(this, arguments);
@@ -316,7 +313,7 @@ define(function (require, exports, module) {
316313
// ensureVisibility is set to false because we don't want to scroll the main editor when the user selects a view
317314
this.sizeInlineWidgetToContents(true, false);
318315

319-
this._updateSelectedMarker();
316+
this._updateSelectedMarker(true);
320317
}
321318

322319
this._updateCommands();
@@ -378,7 +375,7 @@ define(function (require, exports, module) {
378375
// If the selected range is below, we need to update the index
379376
if (index < this._selectedRangeIndex) {
380377
this._selectedRangeIndex--;
381-
this._updateSelectedMarker();
378+
this._updateSelectedMarker(true);
382379
}
383380

384381
if (this._ranges.length === 1) {
@@ -434,7 +431,7 @@ define(function (require, exports, module) {
434431
this._updateCommands();
435432
};
436433

437-
MultiRangeInlineEditor.prototype._updateSelectedMarker = function () {
434+
MultiRangeInlineEditor.prototype._updateSelectedMarker = function (animate) {
438435
if (this._selectedRangeIndex < 0) {
439436
return new $.Deferred().resolve().promise();
440437
}
@@ -449,8 +446,10 @@ define(function (require, exports, module) {
449446
itemTop = $rangeItem.position().top,
450447
scrollTop = self.$relatedContainer.scrollTop();
451448

452-
self.$selectedMarker.css("top", itemTop);
453-
self.$selectedMarker.height($rangeItem.outerHeight());
449+
self.$selectedMarker
450+
.toggleClass("animate", animate)
451+
.css("top", itemTop)
452+
.height($rangeItem.outerHeight());
454453

455454
if (containerHeight <= 0) {
456455
return;
@@ -614,6 +613,15 @@ define(function (require, exports, module) {
614613
}
615614
};
616615

616+
/**
617+
* Called when the editor containing the inline is made visible. Updates UI based on
618+
* state that might have changed while the editor was hidden.
619+
*/
620+
MultiRangeInlineEditor.prototype.onParentShown = function () {
621+
MultiRangeInlineEditor.prototype.parentClass.onParentShown.apply(this, arguments);
622+
this._updateSelectedMarker(false);
623+
};
624+
617625
/**
618626
* Refreshes the height of the inline editor and all child editors.
619627
* @override

0 commit comments

Comments
 (0)