<commit_before>iD.ui.preset = function(context) {
    var event = d3.dispatch('change', 'setTags', 'close'),
        entity,
        tags,
        keys,
        preset,
        formwrap,
        formbuttonwrap;

    function input(d) {
        var i = iD.ui.preset[d.type](d, context)
            .on('close', event.close)
            .on('change', event.change);

        event.on('setTags.' + d.key || d.type, function(tags) {
            i.tags(_.clone(tags));
        });

        if (d.type === 'address') i.entity(entity);

        keys = keys.concat(d.key ? [d.key] : d.keys);

        d3.select(this).call(i);
    }

    function presets(selection) {

        selection.html('');
        keys = [];

        formwrap = selection.append('div');

        var geometry = entity.geometry(context.graph());
        draw(formwrap, preset.fields.filter(function(f) {
            return f.matchGeometry(geometry);
        }));

        var wrap = selection.append('div')
            .attr('class', 'col12 more-buttons inspector-inner');

       formbuttonwrap = wrap.append('div')
            .attr('class', 'col12 preset-input');

        formbuttonwrap.selectAll('button')
            .data(context.presets().universal())
            .enter()
            .append('button')
                .attr('class', 'preset-add-field')
                .on('click', addForm)
                .each(tooltip)
                .append('span')
                    .attr('class', function(d) { return 'icon ' + d.icon; });

        function tooltip(d) {
            d3.select(this).call(bootstrap.tooltip()
                .placement('top')
                .title(d.label()));
        }

        function addForm(d) {
            draw(formwrap, [d]);
            d3.select(this).remove();
            if (!wrap.selectAll('button').node()) wrap.remove();
        }

        if (!preset.additional || !preset.additional.length) wrap.remove();
    }

    function formKey(d) {
        return d.key || String(d.keys);
    }

    function draw(selection, fields) {
        var sections = selection.selectAll('div.preset-section')
            .data(fields, formKey)
            .enter()
            .append('div')
            .attr('class', 'preset-section fillL inspector-inner col12');

        sections.append('h4')
            .attr('for', function(d) { return 'input-' + d.key; })
            .text(function(d) { return d.label(); });

        sections.each(input);
    }

    presets.rendered = function() {
        return keys;
    };

    presets.preset = function(_) {
        if (!arguments.length) return preset;
        preset = _;
        return presets;
    };

    presets.change = function(t) {
        tags = t;

        function haveKey(k) { return k && !!tags[k]; }

        formbuttonwrap.selectAll('button').each(function(p) {
            if (haveKey(p.key) || _.any(p.keys, haveKey)) {
                draw(formwrap, [p]);
                d3.select(this).remove();
            }
        });

        event.setTags(tags);
        return presets;
    };

    presets.entity = function(_) {
        if (!arguments.length) return entity;
        entity = _;
        return presets;
    };

    return d3.rebind(presets, event, 'on');
};
<commit_msg>Don't show buttons for already displayed fields<commit_after>iD.ui.preset = function(context) {
    var event = d3.dispatch('change', 'setTags', 'close'),
        entity,
        tags,
        keys,
        preset,
        formwrap,
        formbuttonwrap;

    function input(d) {
        var i = iD.ui.preset[d.type](d, context)
            .on('close', event.close)
            .on('change', event.change);

        event.on('setTags.' + d.key || d.type, function(tags) {
            i.tags(_.clone(tags));
        });

        if (d.type === 'address') i.entity(entity);

        keys = keys.concat(d.key ? [d.key] : d.keys);

        d3.select(this).call(i);
    }

    function presets(selection) {

        selection.html('');
        keys = [];

        formwrap = selection.append('div');

        var geometry = entity.geometry(context.graph());
        draw(formwrap, preset.fields.filter(function(f) {
            return f.matchGeometry(geometry);
        }));

        var wrap = selection.append('div')
            .attr('class', 'col12 more-buttons inspector-inner');

        formbuttonwrap = wrap.append('div')
            .attr('class', 'col12 preset-input');

        formbuttonwrap.selectAll('button')
            .data(context.presets().universal().filter(notInForm))
            .enter()
            .append('button')
                .attr('class', 'preset-add-field')
                .on('click', addForm)
                .each(tooltip)
                .append('span')
                    .attr('class', function(d) { return 'icon ' + d.icon; });

        function notInForm(p) {
            return preset.fields.indexOf(p) < 0;
        }

        function tooltip(d) {
            d3.select(this).call(bootstrap.tooltip()
                .placement('top')
                .title(d.label()));
        }

        function addForm(d) {
            draw(formwrap, [d]);
            d3.select(this).remove();
            if (!wrap.selectAll('button').node()) wrap.remove();
        }

    }

    function formKey(d) {
        return d.key || String(d.keys);
    }

    function draw(selection, fields) {
        var sections = selection.selectAll('div.preset-section')
            .data(fields, formKey)
            .enter()
            .append('div')
            .attr('class', 'preset-section fillL inspector-inner col12');

        sections.append('h4')
            .attr('for', function(d) { return 'input-' + d.key; })
            .text(function(d) { return d.label(); });

        sections.each(input);
    }

    presets.rendered = function() {
        return keys;
    };

    presets.preset = function(_) {
        if (!arguments.length) return preset;
        preset = _;
        return presets;
    };

    presets.change = function(t) {
        tags = t;

        function haveKey(k) { return k && !!tags[k]; }

        formbuttonwrap.selectAll('button').each(function(p) {
            if (haveKey(p.key) || _.any(p.keys, haveKey)) {
                draw(formwrap, [p]);
                d3.select(this).remove();
            }
        });

        event.setTags(tags);
        return presets;
    };

    presets.entity = function(_) {
        if (!arguments.length) return entity;
        entity = _;
        return presets;
    };

    return d3.rebind(presets, event, 'on');
};

{'fraction_non_alphanumeric': 0.1581998474446987, 'fraction_numerical': 0.004118993135011442, 'mean_word_length': 1.7373695198329855, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2712284', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1912, 'n_words': 347}