Short-circuiting the render of nodes.
This will reduce the depth of nesting of elements (and hopefully make final positioning easier)
This commit is contained in:
parent
6dcc5f48c4
commit
fc7032241f
@ -5,42 +5,54 @@ export default _.extend({}, Base, {
|
||||
type: 'match',
|
||||
|
||||
render() {
|
||||
this.contents = {};
|
||||
var parts = this.parts();
|
||||
|
||||
if (this.anchorStart()) {
|
||||
this.contents.anchor_start = this.renderLabel(this.container, 'Start of line')
|
||||
.addClass('anchor');
|
||||
}
|
||||
if (this.anchorStart() || this.anchorEnd() || parts.length !== 1) {
|
||||
this.contents = {};
|
||||
|
||||
this.contents.parts = _.map(this.parts(), (function(part) {
|
||||
part.setContainer(this.container.group());
|
||||
part.render();
|
||||
return part;
|
||||
}).bind(this));
|
||||
if (this.anchorStart()) {
|
||||
this.contents.anchor_start = this.renderLabel(this.container, 'Start of line')
|
||||
.addClass('anchor');
|
||||
}
|
||||
|
||||
if (this.anchorEnd()) {
|
||||
this.contents.anchor_end = this.renderLabel(this.container, 'End of line')
|
||||
.addClass('anchor');
|
||||
this.contents.parts = _.map(parts, (function(part) {
|
||||
part.setContainer(this.container.group());
|
||||
part.render();
|
||||
return part;
|
||||
}).bind(this));
|
||||
|
||||
if (this.anchorEnd()) {
|
||||
this.contents.anchor_end = this.renderLabel(this.container, 'End of line')
|
||||
.addClass('anchor');
|
||||
}
|
||||
} else {
|
||||
this.content = parts[0];
|
||||
this.content.setContainer(this.container);
|
||||
this.content.render();
|
||||
}
|
||||
},
|
||||
|
||||
position() {
|
||||
var items;
|
||||
|
||||
if (this.anchorStart()) {
|
||||
this.positionLabel(this.contents.anchor_start);
|
||||
if (this.contents) {
|
||||
if (this.contents.anchor_start) {
|
||||
this.positionLabel(this.contents.anchor_start);
|
||||
}
|
||||
|
||||
if (this.contents.anchor_end) {
|
||||
this.positionLabel(this.contents.anchor_end);
|
||||
}
|
||||
|
||||
_.invoke(this.contents.parts, 'position');
|
||||
|
||||
items = _(this.contents).values().flatten().value();
|
||||
this.spaceHorizontally(items, {
|
||||
padding: 10
|
||||
});
|
||||
} else {
|
||||
this.content.position();
|
||||
}
|
||||
|
||||
if (this.anchorEnd()) {
|
||||
this.positionLabel(this.contents.anchor_end);
|
||||
}
|
||||
|
||||
_.invoke(this.contents.parts, 'position');
|
||||
|
||||
items = _(this.contents).values().flatten().value();
|
||||
this.spaceHorizontally(items, {
|
||||
padding: 10
|
||||
});
|
||||
},
|
||||
|
||||
anchorStart() {
|
||||
|
@ -5,7 +5,11 @@ export default _.extend({}, Base, {
|
||||
type: 'match-fragment',
|
||||
|
||||
render() {
|
||||
this._content.setContainer(this.container.group());
|
||||
if (this._repeat.textValue === '') {
|
||||
this._content.setContainer(this.container);
|
||||
} else {
|
||||
this._content.setContainer(this.container.group());
|
||||
}
|
||||
this._content.render();
|
||||
},
|
||||
|
||||
|
@ -5,13 +5,21 @@ export default _.extend({}, Base, {
|
||||
type: 'regexp',
|
||||
|
||||
render() {
|
||||
this.matchContainer = this.container.group();
|
||||
var matches = this.matches();
|
||||
|
||||
_.each(this.matches(), (match => {
|
||||
match.setContainer(this.matchContainer.group());
|
||||
match.render();
|
||||
return match.container;
|
||||
}).bind(this));
|
||||
if (matches.length === 1) {
|
||||
matches[0].setContainer(this.container);
|
||||
matches[0].render();
|
||||
} else {
|
||||
this.matchContainer = this.container.group()
|
||||
.addClass('regexp-matches');
|
||||
|
||||
_.each(matches, (match => {
|
||||
match.setContainer(this.matchContainer.group());
|
||||
match.render();
|
||||
return match.container;
|
||||
}).bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
position() {
|
||||
@ -22,11 +30,11 @@ export default _.extend({}, Base, {
|
||||
|
||||
_.invoke(matches, 'position');
|
||||
|
||||
this.spaceVertically(matches, {
|
||||
padding: 5
|
||||
});
|
||||
|
||||
if (includeLines) {
|
||||
this.spaceVertically(matches, {
|
||||
padding: 5
|
||||
});
|
||||
|
||||
this.matchContainer.transform(Snap.matrix()
|
||||
.translate(20, 0));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user