<commit_before>module('lively.ide.commands.default').requires().toRun(function() {

Object.extend(lively.ide.commands, {
    byName: {},
    defaultBindings: {},
    exec: function(commandName) {
        var cmd = lively.ide.commands.byName[commandName];
        try {
            return !cmd || !cmd.exec ? null : cmd.exec();
        } catch(err) {
            show('Error when executing command %s:\n %s', commandName, err);
            return false;
        }
    },
    addCommand: function(name, command) {
        if (!command) delete lively.ide.commands.byName[name];
        else lively.ide.commands.byName[name] = command;
    }
});

Object.extend(lively.ide.commands.byName, { // add default commands
    escape: {
        exec: function() {
            // Global Escape will drop grabbed morphs, remove menus, close halos
            var world = lively.morphic.World.current(), h = world.firstHand();
            if (h.submorphs.length > 0) { h.dropContentsOn(world); return true; }
            if (world.worldMenuOpened) { h.removeOpenMenu(event); return true; }
            if (world.currentHaloTarget) { world.removeHalosOfCurrentHaloTarget(); return true; }
            return false;
        }
    },
    closeActiveWindow: {
        exec: function() {
            $world.closeActiveWindow();
            return true;
        }
    },
    windowNavigation: {
        exec: function() {
            lively.ide.WindowNavigation.WindowManager.current().startWindowSelection();
            return true;
        }
    },
    resetKeyBindings: {
        exec: function() {
            lively.ide.WindowNavigation.WindowManager.reset();
            lively.morphic.KeyboardDispatcher.reset();
            return true;
        },
    }
});
Object.extend(lively.ide.commands.defaultBindings, { // bind commands to default keys
    escape: "esc",
    closeActiveWindow: "cmd-esc",
    windowNavigation: {mac: "cmd-`", win: "ctrl-`"},
    resetKeyBindings: 'F8'
});

}) // end of module<commit_msg>ide: doGrepSearch command key binding (cmd-shift-g)<commit_after>module('lively.ide.commands.default').requires().toRun(function() {

Object.extend(lively.ide.commands, {
    byName: {},
    defaultBindings: {},
    exec: function(commandName) {
        var cmd = lively.ide.commands.byName[commandName];
        try {
            return !cmd || !cmd.exec ? null : cmd.exec();
        } catch(err) {
            show('Error when executing command %s:\n %s', commandName, err);
            return false;
        }
    },
    addCommand: function(name, command) {
        if (!command) delete lively.ide.commands.byName[name];
        else lively.ide.commands.byName[name] = command;
    }
});

Object.extend(lively.ide.commands.byName, { // add default commands
    escape: {
        exec: function() {
            // Global Escape will drop grabbed morphs, remove menus, close halos
            var world = lively.morphic.World.current(), h = world.firstHand();
            if (h.submorphs.length > 0) { h.dropContentsOn(world); return true; }
            if (world.worldMenuOpened) { h.removeOpenMenu(event); return true; }
            if (world.currentHaloTarget) { world.removeHalosOfCurrentHaloTarget(); return true; }
            return false;
        }
    },
    closeActiveWindow: {
        exec: function() {
            $world.closeActiveWindow();
            return true;
        }
    },
    windowNavigation: {
        exec: function() {
            lively.ide.WindowNavigation.WindowManager.current().startWindowSelection();
            return true;
        }
    },
    resetKeyBindings: {
        exec: function() {
            lively.ide.WindowNavigation.WindowManager.reset();
            lively.morphic.KeyboardDispatcher.reset();
            delete $world._grepSearcher;
            return true;
        },
    },
    activatePrevSelectionNarrower: {
        exec: function() {
            var n = lively.ide.tools.SelectionNarrowing && lively.ide.tools.SelectionNarrowing.lastActive;
            n && n.activate();
        }
    },
    doGrepSearch: {
        exec: function() {
            // that's just a late night hack!
            // $world._grepSearcher = null
            var w = lively.morphic.World.current();
            if (w._grepSearcher) {
                w._grepSearcher.activate();
                return true;
            }
            if (w.hasOwnProperty('doNotSerialize')) w.doNotSerialize.push('_grepSearcher');
            else w.doNotSerialize = ['_grepSearcher'];
            var narrower = w._grepSearcher = lively.BuildSpec('lively.ide.tools.NarrowingList').createMorph();
            lively.bindings.connect(narrower, 'confirmedSelection', narrower, 'deactivate');
            lively.bindings.connect(narrower, 'escapePressed', narrower, 'deactivate');
            lively.bindings.connect(narrower, 'escapePressed', show.bind('foooo'), 'call');
            var greper = Functions.debounce(500, function(input, callback) {
                lively.ide.CommandLineSearch.doGrep(input, null, function(lines) {
                    callback(lines.asListItemArray());
                })
            });
            var spec = {
                candidatesUpdaterMinLength: 3,
                candidates: Array.range(0,20).invoke('toString'),
                candidatesUpdater: greper,
                actions: [function(candidate) { lively.ide.CommandLineSearch.doBrowseGrepString(candidate); }]
            }
            narrower.open(spec);
            return true;
        }
    }
});

Object.extend(lively.ide.commands.defaultBindings, { // bind commands to default keys
    escape: "esc",
    closeActiveWindow: "cmd-esc",
    windowNavigation: {mac: "cmd-`", win: "ctrl-`"},
    resetKeyBindings: 'F8',
    activatePrevSelectionNarrower: "cmd-y",
    doGrepSearch: "cmd-s-g"
});

}) // end of module
{'fraction_non_alphanumeric': 0.13034553540882654, 'fraction_numerical': 0.001881628463906945, 'mean_word_length': 2.196828868234008, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2252328', 'n_tokens_mistral': 1698, 'n_tokens_neox': 1666, 'n_words': 313}