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,6 +5,9 @@ export default _.extend({}, Base, {
|
||||
type: 'match',
|
||||
|
||||
render() {
|
||||
var parts = this.parts();
|
||||
|
||||
if (this.anchorStart() || this.anchorEnd() || parts.length !== 1) {
|
||||
this.contents = {};
|
||||
|
||||
if (this.anchorStart()) {
|
||||
@ -12,7 +15,7 @@ export default _.extend({}, Base, {
|
||||
.addClass('anchor');
|
||||
}
|
||||
|
||||
this.contents.parts = _.map(this.parts(), (function(part) {
|
||||
this.contents.parts = _.map(parts, (function(part) {
|
||||
part.setContainer(this.container.group());
|
||||
part.render();
|
||||
return part;
|
||||
@ -22,16 +25,22 @@ export default _.extend({}, Base, {
|
||||
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()) {
|
||||
if (this.contents) {
|
||||
if (this.contents.anchor_start) {
|
||||
this.positionLabel(this.contents.anchor_start);
|
||||
}
|
||||
|
||||
if (this.anchorEnd()) {
|
||||
if (this.contents.anchor_end) {
|
||||
this.positionLabel(this.contents.anchor_end);
|
||||
}
|
||||
|
||||
@ -41,6 +50,9 @@ export default _.extend({}, Base, {
|
||||
this.spaceHorizontally(items, {
|
||||
padding: 10
|
||||
});
|
||||
} else {
|
||||
this.content.position();
|
||||
}
|
||||
},
|
||||
|
||||
anchorStart() {
|
||||
|
@ -5,7 +5,11 @@ export default _.extend({}, Base, {
|
||||
type: 'match-fragment',
|
||||
|
||||
render() {
|
||||
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 => {
|
||||
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');
|
||||
|
||||
if (includeLines) {
|
||||
this.spaceVertically(matches, {
|
||||
padding: 5
|
||||
});
|
||||
|
||||
if (includeLines) {
|
||||
this.matchContainer.transform(Snap.matrix()
|
||||
.translate(20, 0));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user