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

Commit 8f3fc7b

Browse files
committed
Merge pull request #7424 from oslego/fix-shapes-update
Fix shapes update
2 parents 31dee88 + 5d6cfe9 commit 8f3fc7b

3 files changed

Lines changed: 24 additions & 26 deletions

File tree

src/extensions/default/CSSShapesEditor/LiveEditorLocalDriver.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ define(function (require, exports, module) {
8686
}
8787

8888
/**
89-
* @private
9089
* Inject remote live editor driver and any specified editor providers.
9190
* The remote live editor driver mirrors most of the local live editor driver API
9291
* to provide an interface to the in-browser live editor.
@@ -104,16 +103,16 @@ define(function (require, exports, module) {
104103
}
105104

106105
/**
107-
* @private
108106
* Send instructions to remove the live editor from the page in LivePreview.
109107
* @return {$.Promise}
110108
*/
111109
function remove() {
112110
if (_hasEditor === false) {
113111
var deferred = $.Deferred();
114-
return deferred.reject();
112+
return deferred.reject().promise();
115113
}
116114

115+
_cache.model = undefined; // do not move in _reset(), otherwise the _reconnect() scenario misses the cache and fails
117116
_reset();
118117
var expr = _namespace + ".remove()";
119118
return _call(expr);
@@ -138,6 +137,10 @@ define(function (require, exports, module) {
138137
hasChanged = false,
139138
key;
140139

140+
if (!data) {
141+
remove();
142+
}
143+
141144
// sync the local model snapshot with the remote model
142145
_.forEach(data, function (value, key) {
143146
if (!_model[key] || !_.isEqual(_model[key], value)) {
@@ -155,18 +158,24 @@ define(function (require, exports, module) {
155158
/**
156159
* @private
157160
* Handle failed promises for eval() calls to the inspected page.
158-
* Promises can fail if the user manually refreshes the page or navigates
161+
* Promises fail if the user manually refreshes the page or navigates
159162
* because the injected editor files will be lost.
163+
* If this is the case, attempt to reconnect.
160164
*
161-
* @param {$.Promise=} result promise result
165+
* Promises also fail because of errors thrown in the remote page.
166+
* If this is the case, remove the editor.
162167
*/
163-
function _whenRemoteCallFailed(result) {
164-
if (result) {
165-
return _reconnect();
166-
} else {
167-
_cache.model = undefined;
168-
return remove();
169-
}
168+
function _whenRemoteCallFailed() {
169+
// check if the remote editor namespace is still defined on the page
170+
_call(_namespace)
171+
.then(function (response) {
172+
if (response.type === "undefined") {
173+
_reconnect();
174+
} else {
175+
remove();
176+
}
177+
})
178+
.fail(remove);
170179
}
171180

172181
/**

src/extensions/default/CSSShapesEditor/thirdparty/CSSShapesEditorProvider.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
Declared globally within module so it can be removed by Provider.remove()
8383
Defined here so it can access scope.inst
8484
85-
Ctrl+T toggles the free transform editor (scale/rotate)
85+
T key toggles the free transform editor (scale/rotate)
8686
Esc key turns off free transform editor; quietly ignored if editor was never turned on.
8787
8888
@param {Event} e keydown event
@@ -92,8 +92,8 @@
9292
if (scope.inst.type !== "polygon") {
9393
return;
9494
}
95-
// Ctrl+T toggles rotate/scale editor
96-
if (e.ctrlKey && e.keyIdentifier === "U+0054") {
95+
// T key toggles rotate/scale editor
96+
if (e.keyIdentifier === "U+0054") {
9797
scope.inst.toggleFreeTransform();
9898
}
9999

src/extensions/default/CSSShapesEditor/unittests.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -466,17 +466,6 @@ define(function (require, exports, module) {
466466

467467
expect(LiveEditorLocalDriver.remove).toHaveBeenCalled();
468468
});
469-
470-
it("should call remove() when LivePreview is turned off", function () {
471-
var deferred = $.Deferred();
472-
spyOn(LiveEditorLocalDriver, "remove").andReturn(deferred.promise());
473-
474-
main._setup();
475-
main._teardown();
476-
477-
expect(LiveEditorLocalDriver.remove).toHaveBeenCalled();
478-
});
479-
480469
});
481470

482471
describe("Live Preview Workflow", function () {

0 commit comments

Comments
 (0)