function makeCtrlAltKeyEvents() { var altGrEvents = [], altEvent = _.cloneDeep(ctrlEvent); altEvent.keyIdentifier = "Alt"; altEvent.altKey = true; altEvent.keyCode = KeyEvent.DOM_VK_ALT; altGrEvents.push(_.cloneDeep(ctrlEvent)); altGrEvents.push(altEvent); return altGrEvents; }
it("should block command execution when right Alt key is pressed following a Ctrl shortcut execution", function () { var ctrlEvent1 = _.cloneDeep(ctrlEvent); // Simulate holding down Ctrl key and execute a Ctrl shortcut in native shell code // No need to call the actual Ctrl shortcut since it is not handled in KBM anyway. KeyBindingManager._handleKeyEvent(ctrlEvent1); ctrlEvent1.repeat = true; KeyBindingManager._handleKeyEvent(ctrlEvent1); KeyBindingManager._handleKeyEvent(ctrlEvent1); // Simulate a right Alt key down with the specific sequence of keydown events. ctrlAltEvents.forEach(function (e) { e.timeStamp = new Date(); e.repeat = false; KeyBindingManager._handleKeyEvent(e); }); // Simulate the command shortcut KeyBindingManager._handleKeyEvent(ctrlAlt1Event); expect(commandCalled).toBe(false); // In this case, the event should not have been stopped, because KBM didn't handle it. expect(ctrlAlt1Event.immediatePropagationStopped).toBe(false); expect(ctrlAlt1Event.propagationStopped).toBe(false); expect(ctrlAlt1Event.defaultPrevented).toBe(false); // Now explicitly remove the keyup event listener created by _detectAltGrKeyDown function. KeyBindingManager._onCtrlUp(ctrlEvent); });
self.updateColorState = function () { debug_log('updateColorState'); if (_.isEqual(client_state.colors, colors.colors)) return; client_state.colors = _.cloneDeep(colors.colors); self.setDirty({colors: true}); };
self.updateControlState = function () { debug_log('updateControlState'); if (_.isEqual(client_state.control, self.control)) return; client_state.control = _.cloneDeep(self.control); self.setDirty({control: true}); };
self.updateSystemState = function () { debug_log('updateSystemState'); if (_.isEqual(client_state.system, self.system)) return; client_state.system = _.cloneDeep(self.system); self.setDirty({system: true}); };
self.updateArmyState = function () { debug_log('updateArmyState'); var armies = _.invoke(self.armies, 'asJson'); if (_.isEqual(client_state.armies, armies)) return; client_state.armies = _.cloneDeep(armies); self.setDirty({ armies: true }); };
self.updateSettingsState = function () { debug_log('updateSettingsState'); if (_.isEqual(client_state.settings, self.settings)) return; client_state.settings = _.cloneDeep(self.settings); main.spectators = Number(self.settings.spectators); self.setDirty({ settings: true }); };
self.updatePlayerState = function () { debug_log('updatePlayerState'); var players = _.invoke(self.players, 'asJson'); if (_.isEqual(client_state.players, players)) return; client_state.players = _.cloneDeep(players); self.setDirty({players: true}); self.watchdog.updatePlayerState(); };
Object.keys(prefs).forEach(function (key) { if (convertedKeys.indexOf(key) > -1) { return; } var rule = rules[key]; if (!rule && prefCheckCallback) { rule = prefCheckCallback(key); } else if (prefCheckCallback) { // Check whether we have a new preference key-value pair // for an old preference. var newRule = prefCheckCallback(key, prefs[key]); if (newRule) { rule = _.cloneDeep(newRule); } } if (!rule) { console.warn("Preferences conversion for ", self._clientID, " has no rule for", key); complete = false; } else if (_.isString(rule)) { var parts = rule.split(" "); if (parts[0] === "user") { var newKey = parts.length > 1 ? parts[1] : key; var options = null; if (parts.length > 2 && parts[2].indexOf("/") !== -1) { var projectPath = rule.substr(rule.indexOf(parts[2])); options = { location: { scope: "user", layer: "project", layerID: projectPath } }; } manager.set(newKey, prefs[key], options); convertedKeys.push(key); } } else if (_.isObject(rule)) { Object.keys(rule).forEach(function (ruleKey) { manager.set(ruleKey, rule[ruleKey]); }); convertedKeys.push(key); } else { complete = false; } });
/** * @private * Finish a replace across files operation when the user clicks "Replace" on the results panel. * @param {SearchModel} model The model for the search associated with ths replace. */ function _finishReplaceAll(model) { var replaceText = model.replaceText; if (replaceText === null) { return; } // Clone the search results so that they don't get updated in the middle of the replacement. var resultsClone = _.cloneDeep(model.results), replacedFiles = Object.keys(resultsClone).filter(function (path) { return FindUtils.hasCheckedMatches(resultsClone[path]); }), isRegexp = model.queryInfo.isRegexp; function processReplace(forceFilesOpen) { StatusBar.showBusyIndicator(true); FindInFiles.doReplace(resultsClone, replaceText, { forceFilesOpen: forceFilesOpen, isRegexp: isRegexp }) .fail(function (errors) { var message = Strings.REPLACE_IN_FILES_ERRORS + FileUtils.makeDialogFileList( errors.map(function (errorInfo) { return ProjectManager.makeProjectRelativeIfPossible(errorInfo.item); }) ); Dialogs.showModalDialog( DefaultDialogs.DIALOG_ID_ERROR, Strings.REPLACE_IN_FILES_ERRORS_TITLE, message, [ { className : Dialogs.DIALOG_BTN_CLASS_PRIMARY, id : Dialogs.DIALOG_BTN_OK, text : Strings.BUTTON_REPLACE_WITHOUT_UNDO } ] ); }) .always(function () { StatusBar.hideBusyIndicator(); }); } if (replacedFiles.length <= MAX_IN_MEMORY) { // Just do the replacements in memory. _resultsView.close(); processReplace(true); } else { Dialogs.showModalDialog( DefaultDialogs.DIALOG_ID_INFO, Strings.REPLACE_WITHOUT_UNDO_WARNING_TITLE, StringUtils.format(Strings.REPLACE_WITHOUT_UNDO_WARNING, MAX_IN_MEMORY), [ { className : Dialogs.DIALOG_BTN_CLASS_NORMAL, id : Dialogs.DIALOG_BTN_CANCEL, text : Strings.CANCEL }, { className : Dialogs.DIALOG_BTN_CLASS_PRIMARY, id : Dialogs.DIALOG_BTN_OK, text : Strings.BUTTON_REPLACE_WITHOUT_UNDO } ] ) .done(function (id) { if (id === Dialogs.DIALOG_BTN_OK) { _resultsView.close(); processReplace(false); } }); } }
/** * @private * * Initializes _allCommands array and _defaultKeyMap so that we can use them for * detecting non-existent commands and restoring the original key binding. * * @param {string} fullPath file path to the user key map file. */ function _initCommandAndKeyMaps() { _allCommands = CommandManager.getAll(); // Keep a copy of the default key bindings before loading user key bindings. _defaultKeyMap = _.cloneDeep(_keyMap); }
.then(function (keyMap) { _customKeyMapCache = _.cloneDeep(_customKeyMap); _customKeyMap = keyMap; _undoPriorUserKeyBindings(); _applyUserKeyBindings(); }, function (err) {
Document.prototype.doMultipleEdits = function (edits, origin) { var self = this; // Sort the edits backwards, so we don't have to adjust the edit positions as we go along // (though we do have to adjust the selection positions). edits.sort(function (editDesc1, editDesc2) { var edit1 = (Array.isArray(editDesc1.edit) ? editDesc1.edit[0] : editDesc1.edit), edit2 = (Array.isArray(editDesc2.edit) ? editDesc2.edit[0] : editDesc2.edit); // Treat all no-op edits as if they should happen before all other edits (the order // doesn't really matter, as long as they sort out of the way of the real edits). if (!edit1) { return -1; } else if (!edit2) { return 1; } else { return CodeMirror.cmpPos(edit2.start, edit1.start); } }); // Pull out the selections, in the same order as the edits. var result = _.cloneDeep(_.pluck(edits, "selection")); // Preflight the edits to specify "end" if unspecified and make sure they don't overlap. // (We don't want to do it during the actual edits, since we don't want to apply some of // the edits before we find out.) _.each(edits, function (editDesc, index) { oneOrEach(editDesc.edit, function (edit) { if (edit) { if (!edit.end) { edit.end = edit.start; } if (index > 0) { var prevEditGroup = edits[index - 1].edit; // The edits are in reverse order, so we want to make sure this edit ends // before any of the previous ones start. oneOrEach(prevEditGroup, function (prevEdit) { if (CodeMirror.cmpPos(edit.end, prevEdit.start) > 0) { throw new Error("Document.doMultipleEdits(): Overlapping edits specified"); } }); } } }); }); // Perform the edits. this.batchOperation(function () { _.each(edits, function (editDesc, index) { // Perform this group of edits. The edit positions are guaranteed to be okay // since all the previous edits we've done have been later in the document. However, // we have to fix up any selections that overlap or come after the edit. oneOrEach(editDesc.edit, function (edit) { if (edit) { self.replaceRange(edit.text, edit.start, edit.end, origin); // Fix up all the selections *except* the one(s) related to this edit list that // are not "before-edit" selections. var textLines = edit.text.split("\n"); _.each(result, function (selections, selIndex) { if (selections) { oneOrEach(selections, function (sel) { if (sel.isBeforeEdit || selIndex !== index) { sel.start = self.adjustPosForChange(sel.start, textLines, edit.start, edit.end); sel.end = self.adjustPosForChange(sel.end, textLines, edit.start, edit.end); } }); } }); } }); }); }); result = _.chain(result) .filter(function (item) { return item !== undefined; }) .flatten() .sort(function (sel1, sel2) { return CodeMirror.cmpPos(sel1.start, sel2.start); }) .value(); _.each(result, function (item) { delete item.isBeforeEdit; }); return result; };
var system = (function() { var ladderSystems = require('lobby/ladder_systems_table').data; return _.cloneDeep(_.sample(ladderSystems)); })();