Skip to content

Commit b8a88f0

Browse files
committed
Editor: Make sure effects names are unique.
1 parent 04b6983 commit b8a88f0

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

css/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ select.Select {
6868
border-radius: 4px;
6969
}
7070

71+
select.Select:focus {
72+
outline: none;
73+
}
74+
7175
.CodeMirror {
7276
position: absolute !important;
7377
top: 37px;

js/Editor.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ Editor.prototype = {
283283

284284
addEffect: function ( effect ) {
285285

286+
makeNameUnique( this.effects, effect );
287+
286288
this.effects.push( effect );
287289
this.signals.effectAdded.dispatch( effect );
288290

@@ -548,6 +550,24 @@ Editor.prototype = {
548550

549551
}
550552

553+
function makeNameUnique( array, item ) {
554+
555+
if ( array.some( e => e.name === item.name ) ) {
556+
557+
let counter = 1;
558+
let newName = item.name + ' ' + counter;
559+
560+
while ( array.some( e => e.name === newName ) ) {
561+
counter++;
562+
newName = item.name + ' ' + counter;
563+
}
564+
565+
item.name = newName;
566+
567+
}
568+
569+
}
570+
551571
function fixLegacyJSON( json ) {
552572

553573
const scripts = json.scripts;

js/SidebarProject.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ function SidebarProject( editor ) {
9595
container.add( new UIText( 'Effects' ).setTextTransform( 'uppercase' ) );
9696
container.add( new UIBreak(), new UIBreak() );
9797

98-
var effects = new UISelect().setMultiple( true ).setWidth( '280px' ).setMarginBottom( '8px' );
98+
var effects = new UISelect().setWidth( '280px' ).setMarginBottom( '8px' );
99+
effects.onChange( function () {
100+
editor.selectEffect( editor.effects[ this.getValue() ] );
101+
} );
99102
container.add( effects );
100103

101-
var cleanEffects = new UIButton( 'Clean Effects' );
104+
var cleanEffects = new UIButton( 'Remove unused' );
102105
cleanEffects.onClick( function () {
103106

104107
editor.cleanEffects();

0 commit comments

Comments
 (0)