Skip to content

Commit

Permalink
Remove connections from the interactive to contained morph upon deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
linusha committed Sep 14, 2021
1 parent 633d230 commit e393f24
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ export class InteractivesEditor extends QinoqMorph {
const sequenceProps = { ...sequence._morphicState, submorphs: [], animations: [], start, layer };
const newSequence = new Sequence(sequenceProps);
morphs.forEach(morph => {
// morph.copy also copies connections
// this is undesirable for us which is why we copy the morph without connections
// and restore the original ones later
// TODO: only filter our connections, maybe some are wanted
const connections = morph.attributeConnections;
morph.attributeConnections = [];
const copiedMorph = morph.copy();
Expand Down Expand Up @@ -549,6 +553,7 @@ export class InteractivesEditor extends QinoqMorph {
prepareToRemoveMorph (morph, sequenceOfMorph) {
disconnect(morph, 'onRemove', this, 'moveMorphOutOfInteractive');
disconnect(morph, 'onAbandon', this, 'removeMorphFromInteractive');

const tab = this.getTabFor(sequenceOfMorph);
if (tab) {
const timeline = this.getTimelineFor(tab);
Expand Down Expand Up @@ -951,7 +956,7 @@ export class InteractivesEditor extends QinoqMorph {
pasteMorphFromClipboard () {
const { morph, animations } = this.clipboard.content;

// morph.copy also copied connections
// morph.copy also copies connections
// this is undesirable for us which is why we copy the morph without connections
// and restore the original ones later
// TODO: only filter our connections, maybe some are wanted
Expand Down
7 changes: 7 additions & 0 deletions interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,13 @@ export class Sequence extends DeserializationAwareMorph {
* while not calling abandon on the morph
**/
abandonMorph (morph, doNotAbandonMorph = false) {
// remove all custom connection from the interactive to the morph to be removed
this.interactive.attributeConnections.forEach(connection => {
console.log(connection.targetObj.id);
if (connection.targetObj == morph) {
disconnect(this.interactive, connection.sourceAttrName, morph, connection.targetMethodName);
}
});
if (doNotAbandonMorph) {
if (morph._fontRatio) delete morph._fontRatio;
morph.remove();
Expand Down
16 changes: 16 additions & 0 deletions tests/editor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { serialize, deserialize } from 'lively.serializer2';
import { LottieMorph } from '../interactive-morphs/lottie-morph.js';
import { Morph } from 'lively.morphic';
import { promise } from 'lively.lang';
import { connect } from 'lively.bindings';

let editor, interactive;
function closeEditor () {
Expand Down Expand Up @@ -36,6 +37,21 @@ describe('Editor', () => {
return editor.withAllSubmorphsSelect(morph => morph.isTimelineSequence);
}

it('interactive removes connections from interactive when target gets removed', async () => {
const newMorph = new Morph();
const dayBackgroundTimelineSequence = timelineSequences().find(timelineSequence => timelineSequence.sequence.name == 'day background');
await dayBackgroundTimelineSequence.openSequenceView();
editor.addMorphToInteractive(newMorph);

const connectionCount = editor.interactive.attributeConnections.length;
connect(interactive, 'onScrollChange', newMorph, 'visible');

expect(interactive.attributeConnections.length).to.be.equal(connectionCount + 1);
newMorph.abandon();

expect(interactive.attributeConnections.length).to.be.equal(connectionCount);
});

describe('with global timeline', () => {
it('sets _lastSelectedTimelineSequence on the first click on a single sequence', () => {
const nightBackgroundTimelineSequence = timelineSequences().find(timelineSequence => timelineSequence.sequence.name == 'night background');
Expand Down

0 comments on commit e393f24

Please sign in to comment.