-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modeling): delete empty text boxes
Closes #6
- Loading branch information
Niklas Kiefer
committed
May 24, 2020
1 parent
6c1a7bd
commit 55e68bd
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import inherits from 'inherits'; | ||
|
||
import { | ||
is | ||
} from '../../../util/ModelUtil'; | ||
|
||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; | ||
|
||
|
||
export default function EmptyTextBoxBehavior(eventBus, modeling) { | ||
|
||
CommandInterceptor.call(this, eventBus); | ||
|
||
// delete text box if it has no text | ||
this.postExecute('element.updateLabel', function(context) { | ||
|
||
var element = context.element, | ||
newLabel = context.newLabel; | ||
|
||
if (is(element, 'postit:TextBox') && isEmpty(newLabel)) { | ||
modeling.removeElements([ element ]); | ||
} | ||
}, true); | ||
} | ||
|
||
inherits(EmptyTextBoxBehavior, CommandInterceptor); | ||
|
||
EmptyTextBoxBehavior.$inject = [ | ||
'eventBus', | ||
'modeling' | ||
]; | ||
|
||
|
||
// helpers ////////// | ||
|
||
function isEmpty(label) { | ||
return !label || label === ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters