<commit_before>iD.ui.PresetGrid = function(context) {
    var event = d3.dispatch('choose', 'close'),
        entity,
        presets = context.presets(),
        taginfo = iD.taginfo();

    function presetgrid(selection, preset) {

        selection.html('');

        presets = presets.matchType(entity, context.graph());

        var messagewrap = selection.append('div')
            .attr('class', 'message inspector-inner fillL');

        var message = messagewrap.append('h3')
            .text(t('inspector.choose'));

        var searchwrap = selection.append('div')
            .attr('class', 'preset-grid-search-wrap inspector-inner');

        var grid = selection.append('div')
            .attr('class', 'preset-grid fillD inspector-body inspector-body-' + entity.geometry(context.graph()))
            .call(drawGrid, context.presets().defaults(entity, 12));

        searchwrap.append('span').attr('class', 'icon search');

        var search = searchwrap.append('input')
            .attr('class', 'preset-grid-search major')
            .attr('placeholder','Search')
            .attr('type', 'search')
            .one('keydown', function() {
                // hack to let delete shortcut work when search is autofocused
                if (search.property('value').length === 0 &&
                    (d3.event.keyCode === d3.keybinding.keyCodes['⌫'] ||
                     d3.event.keyCode === d3.keybinding.keyCodes['⌦'])) {
                    d3.event.preventDefault();
                    d3.event.stopPropagation();
                    iD.operations.Delete([entity.id], context)();
                }
            })
            .on('keyup', function() {
                // enter
                var value = search.property('value');
                if (d3.event.keyCode === 13 && value.length) {
                    choose(grid.selectAll('.grid-entry:first-child').datum());
                } else {
                    grid.classed('filtered', value.length);
                    if (value.length) {
                        var results = presets.search(value);
                        message.text(t('inspector.results', {n: results.collection.length, search: value}));
                        grid.call(drawGrid, results);
                    } else {
                        grid.call(drawGrid, context.presets().defaults(entity, 12));
                    }<commit_msg>More keydown hacks (fixes #923)<commit_after>iD.ui.PresetGrid = function(context) {
    var event = d3.dispatch('choose', 'close'),
        entity,
        presets = context.presets(),
        taginfo = iD.taginfo();

    function presetgrid(selection, preset) {

        selection.html('');

        presets = presets.matchType(entity, context.graph());

        var messagewrap = selection.append('div')
            .attr('class', 'message inspector-inner fillL');

        var message = messagewrap.append('h3')
            .text(t('inspector.choose'));

        var searchwrap = selection.append('div')
            .attr('class', 'preset-grid-search-wrap inspector-inner');

        var grid = selection.append('div')
            .attr('class', 'preset-grid fillD inspector-body inspector-body-' + entity.geometry(context.graph()))
            .call(drawGrid, context.presets().defaults(entity, 12));

        searchwrap.append('span').attr('class', 'icon search');

        var search = searchwrap.append('input')
            .attr('class', 'preset-grid-search major')
            .attr('placeholder','Search')
            .attr('type', 'search')
            .on('keydown', function() {
                // hack to let delete shortcut work when search is autofocused
                if (search.property('value').length === 0 &&
                    (d3.event.keyCode === d3.keybinding.keyCodes['⌫'] ||
                     d3.event.keyCode === d3.keybinding.keyCodes['⌦'])) {
                    d3.event.preventDefault();
                    d3.event.stopPropagation();
                    iD.operations.Delete([entity.id], context)();
                } else if (search.property('value').length === 0 &&
                    (d3.event.ctrlKey || d3.event.metaKey) &&
                    d3.event.keyCode === d3.keybinding.keyCodes['z']) {
                    d3.event.preventDefault();
                    d3.event.stopPropagation();
                    context.undo();
                } else if (!d3.event.ctrlKey && !d3.event.metaKey) {
                    d3.select(this).on('keydown', null);
                }
            })
            .on('keyup', function() {
                // enter
                var value = search.property('value');
                if (d3.event.keyCode === 13 && value.length) {
                    choose(grid.selectAll('.grid-entry:first-child').datum());
                } else {
                    grid.classed('filtered', value.length);
                    if (value.length) {
                        var results = presets.search(value);
                        message.text(t('inspector.results', {n: results.collection.length, search: value}));
                        grid.call(drawGrid, results);
                    } else {
                        grid.call(drawGrid, context.presets().defaults(entity, 12));
                    }
{'fraction_non_alphanumeric': 0.1496018202502844, 'fraction_numerical': 0.008532423208191127, 'mean_word_length': 1.6954522227899846, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3589963', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1362, 'n_words': 245}