Only update inspector tag list when necessary

This commit is contained in:
Ansis Brammanis
2013-01-17 10:48:42 -05:00
parent cdbe3d6168
commit b8d9741959
2 changed files with 18 additions and 13 deletions

View File

@@ -87,11 +87,12 @@ iD.modes.Select = function (entity) {
// Exit mode if selected entity gets undone
mode.history.on('change.entity-undone', function() {
var old = entity;
entity = mode.history.graph().entity(entity.id);
if (!entity) {
mode.controller.enter(iD.modes.Browse());
} else {
d3.select('.inspector-wrap').datum(entity).call(inspector);
} else if(!_.isEqual(entity.tags, old.tags)) {
inspector.tags(entity.tags);
}
});

View File

@@ -99,7 +99,8 @@ iD.ui.inspector = function() {
tags = [{key: '', value: ''}];
}
var li = tagList.selectAll('li')
var li = tagList.html('')
.selectAll('li')
.data(tags, function(d) { return d.key; });
li.exit().remove();
@@ -154,7 +155,6 @@ iD.ui.inspector = function() {
if (en.on_node) types.push('point');
if (en.on_way) types.push('line');
en.types = types;
console.log(en);
iD.ui.modal()
.select('.content')
.datum(en)
@@ -256,15 +256,19 @@ iD.ui.inspector = function() {
event.close(entity);
}
inspector.tags = function () {
var tags = {};
tagList.selectAll('li').each(function() {
var row = d3.select(this),
key = row.selectAll('.key').property('value'),
value = row.selectAll('.value').property('value');
if (key !== '') tags[key] = value;
});
return tags;
inspector.tags = function (tags) {
if (!arguments.length) {
var tags = {};
tagList.selectAll('li').each(function() {
var row = d3.select(this),
key = row.selectAll('.key').property('value'),
value = row.selectAll('.value').property('value');
if (key !== '') tags[key] = value;
});
return tags;
} else {
drawTags(tags);
}
};
return d3.rebind(inspector, event, 'on');