Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into minify-668503
Browse files Browse the repository at this point in the history
  • Loading branch information
joewalker committed Oct 13, 2012
2 parents 1789142 + 440410d commit 0f8e268
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 45 deletions.
68 changes: 37 additions & 31 deletions lib/gcli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ function Requisition(environment, doc) {
// The command that we are about to execute.
// @see setCommandConversion()
this.commandAssignment = new CommandAssignment();
this._setAssignment(this.commandAssignment, null, true);
this.setAssignment(this.commandAssignment, null);

// The object that stores of Assignment objects that we are filling out.
// The Assignment objects are stored under their param.name for named
Expand Down Expand Up @@ -485,7 +485,7 @@ Requisition.prototype._commandAssignmentChanged = function(ev) {
for (var i = 0; i < command.params.length; i++) {
var param = command.params[i];
var assignment = new Assignment(param, i);
this._setAssignment(assignment, null, true);
this.setAssignment(assignment, null);
assignment.onAssignmentChange.add(this._assignmentChanged, this);
this._assignments[param.name] = assignment;
}
Expand Down Expand Up @@ -607,27 +607,23 @@ Requisition.prototype.getAssignments = function(includeCommand) {
return assignments;
};

/**
* Alter the given assignment using the given arg.
* @param assignment The assignment to alter
* @param arg The new value for the assignment. An instance of Argument, or an
* instance of Conversion, or null to set the blank value.
*/
Requisition.prototype.setAssignment = function(assignment, arg) {
this._setAssignment(assignment, arg, false);
};

/**
* Internal function to alter the given assignment using the given arg.
* @param assignment The assignment to alter
* @param arg The new value for the assignment. An instance of Argument, or an
* instance of Conversion, or null to set the blank value.
* @param skipArgUpdate (default=false) Adjusts the args in this requisition to
* keep things up to date. Args should only be skipped when setAssignment is
* being called as part of the update process.
* @param options There are a number of ways to customize how the assignment
* is made, including:
* - argUpdate: (default:false) Adjusts the args in this requisition to keep
* things up to date. Args should only be skipped when setAssignment is being
* called as part of the update process.
* - matchPadding: (default:false) If argUpdate=true, and matchPadding=true
* then further take the step of altering the whitespace on the prefix and
* suffix of the new argument to match that of the old argument.
*/
Requisition.prototype._setAssignment = function(assignment, arg, skipArgUpdate) {
if (!skipArgUpdate) {
Requisition.prototype.setAssignment = function(assignment, arg, options) {
options = options || {};
if (options.argUpdate) {
var originalArgs = assignment.arg.getArgs();

// Update the args array
Expand All @@ -653,6 +649,16 @@ Requisition.prototype._setAssignment = function(assignment, arg, skipArgUpdate)
this._args.splice(index, 1);
}
else {
if (options.matchPadding) {
if (replacementArgs[i].prefix.length === 0 &&
this._args[index].prefix.length !== 0) {
replacementArgs[i].prefix = this._args[index].prefix;
}
if (replacementArgs[i].suffix.length === 0 &&
this._args[index].suffix.length !== 0) {
replacementArgs[i].suffix = this._args[index].suffix;
}
}
this._args[index] = replacementArgs[i];
}
}
Expand Down Expand Up @@ -690,7 +696,7 @@ Requisition.prototype._setAssignment = function(assignment, arg, skipArgUpdate)
*/
Requisition.prototype.setBlankArguments = function() {
this.getAssignments().forEach(function(assignment) {
this._setAssignment(assignment, null, true);
this.setAssignment(assignment, null);
}, this);
};

Expand Down Expand Up @@ -730,13 +736,13 @@ Requisition.prototype.complete = function(cursor, predictionChoice) {
// logic, so we don't use addSpace
if (assignment.isInName()) {
var newArg = assignment.conversion.arg.beget({ prefixPostSpace: true });
this.setAssignment(assignment, newArg);
this.setAssignment(assignment, newArg, { argUpdate: true });
}
}
else {
// Mutate this argument to hold the completion
var arg = assignment.arg.beget({ text: prediction.name });
this.setAssignment(assignment, arg);
this.setAssignment(assignment, arg, { argUpdate: true });

if (!prediction.incomplete) {
// The prediction is complete, add a space to let the user move-on
Expand All @@ -761,7 +767,7 @@ Requisition.prototype.complete = function(cursor, predictionChoice) {
Requisition.prototype._addSpace = function(assignment) {
var arg = assignment.conversion.arg.beget({ suffixSpace: true });
if (arg !== assignment.conversion.arg) {
this.setAssignment(assignment, arg);
this.setAssignment(assignment, arg, { argUpdate: true });
}
};

Expand All @@ -773,7 +779,7 @@ Requisition.prototype.decrement = function(assignment) {
if (replacement != null) {
var str = assignment.param.type.stringify(replacement);
var arg = assignment.conversion.arg.beget({ text: str });
this.setAssignment(assignment, arg);
this.setAssignment(assignment, arg, { argUpdate: true });
}
};

Expand All @@ -785,7 +791,7 @@ Requisition.prototype.increment = function(assignment) {
if (replacement != null) {
var str = assignment.param.type.stringify(replacement);
var arg = assignment.conversion.arg.beget({ text: str });
this.setAssignment(assignment, arg);
this.setAssignment(assignment, arg, { argUpdate: true });
}
};

Expand Down Expand Up @@ -1443,7 +1449,7 @@ Requisition.prototype._split = function(args) {
// Special case: if the user enters { console.log('foo'); } then we need to
// use the hidden 'eval' command
conversion = new Conversion(evalCommand, new ScriptArgument());
this._setAssignment(this.commandAssignment, conversion, true);
this.setAssignment(this.commandAssignment, conversion);
return;
}

Expand All @@ -1470,7 +1476,7 @@ Requisition.prototype._split = function(args) {
argsUsed++;
}

this._setAssignment(this.commandAssignment, conversion, true);
this.setAssignment(this.commandAssignment, conversion);

for (var i = 0; i < argsUsed; i++) {
args.shift();
Expand Down Expand Up @@ -1517,7 +1523,7 @@ Requisition.prototype._assign = function(args) {
var assignment = this.getAssignment(0);
if (assignment.param.type instanceof StringType) {
var arg = (args.length === 1) ? args[0] : new MergedArgument(args);
this._setAssignment(assignment, arg, true);
this.setAssignment(assignment, arg);
return;
}
}
Expand Down Expand Up @@ -1562,7 +1568,7 @@ Requisition.prototype._assign = function(args) {
arrayArg.addArgument(arg);
}
else {
this._setAssignment(assignment, arg, true);
this.setAssignment(assignment, arg);
}
}
else {
Expand All @@ -1579,7 +1585,7 @@ Requisition.prototype._assign = function(args) {
// If not set positionally, and we can't set it non-positionally,
// we have to default it to prevent previous values surviving
if (!assignment.param.isPositionalAllowed) {
this._setAssignment(assignment, null, true);
this.setAssignment(assignment, null);
return;
}

Expand All @@ -1596,7 +1602,7 @@ Requisition.prototype._assign = function(args) {
}
else {
if (args.length === 0) {
this._setAssignment(assignment, null, true);
this.setAssignment(assignment, null);
}
else {
var arg = args.splice(0, 1)[0];
Expand All @@ -1610,7 +1616,7 @@ Requisition.prototype._assign = function(args) {
this._unassigned.push(new UnassignedAssignment(this, arg));
}
else {
this._setAssignment(assignment, arg, true);
this.setAssignment(assignment, arg);
}
}
}
Expand All @@ -1619,7 +1625,7 @@ Requisition.prototype._assign = function(args) {
// Now we need to assign the array argument (if any)
Object.keys(arrayArgs).forEach(function(name) {
var assignment = this.getAssignment(name);
this._setAssignment(assignment, arrayArgs[name], true);
this.setAssignment(assignment, arrayArgs[name]);
}, this);

// What's left is can't be assigned, but we need to extract
Expand Down
3 changes: 2 additions & 1 deletion lib/gcli/ui/arg_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ ArgFetcher.prototype.getInputFor = function(assignment) {

// BUG 664198 - remove on delete
newField.onFieldChange.add(function(ev) {
this.requisition.setAssignment(assignment, ev.conversion.arg);
var options = { argUpdate: true, matchPadding: true };
this.requisition.setAssignment(assignment, ev.conversion.arg, options);
}, this);
assignment.onAssignmentChange.add(function(ev) {
newField.setConversion(ev.conversion);
Expand Down
6 changes: 4 additions & 2 deletions lib/gcli/ui/fields/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ JavascriptField.prototype.setConversion = function(conversion) {
};

JavascriptField.prototype.itemClicked = function(ev) {
this.onFieldChange(ev);
this.setMessage(ev.conversion.message);
var conversion = this.type.parse(ev.arg);

this.onFieldChange({ conversion: conversion });
this.setMessage(conversion.message);
};

JavascriptField.prototype.onInputChange = function(ev) {
Expand Down
13 changes: 6 additions & 7 deletions lib/gcli/ui/fields/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ Menu.prototype.onItemClickInternal = function(ev) {
var arg = new Argument(name);
arg.suffix = ' ';

var conversion = this.type.parse(arg);
this.onItemClick({ conversion: conversion });
this.onItemClick({ arg: arg });
};

/**
Expand All @@ -112,7 +111,7 @@ Menu.prototype.show = function(items, match) {

if (match) {
this.items = this.items.map(function(item) {
return gethighlightingProxy(item, match, this.template.ownerDocument);
return getHighlightingProxy(item, match, this.template.ownerDocument);
}.bind(this));
}

Expand All @@ -138,7 +137,7 @@ Menu.prototype.show = function(items, match) {
/**
* Create a proxy around an item that highlights matching text
*/
function gethighlightingProxy(item, match, document) {
function getHighlightingProxy(item, match, document) {
if (typeof Proxy === 'undefined') {
return item;
}
Expand Down Expand Up @@ -200,12 +199,12 @@ Menu.prototype.selectChoice = function() {
return false;
}

var name = selected.innerHTML;
var name = selected.textContent;
var arg = new Argument(name);
arg.suffix = ' ';
arg.prefix = ' ';

var conversion = this.type.parse(arg);
this.onItemClick({ conversion: conversion });
this.onItemClick({ arg: arg });
return true;
};

Expand Down
6 changes: 4 additions & 2 deletions lib/gcli/ui/fields/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ SelectionTooltipField.prototype.setConversion = function(conversion) {
};

SelectionTooltipField.prototype.itemClicked = function(ev) {
this.onFieldChange(ev);
this.setMessage(ev.conversion.message);
var conversion = this.type.parse(ev.arg);

this.onFieldChange({ conversion: conversion });
this.setMessage(conversion.message);
};

SelectionTooltipField.prototype.onInputChange = function(ev) {
Expand Down
3 changes: 2 additions & 1 deletion lib/gcli/ui/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ Tooltip.prototype.selectChoice = function(ev) {
* Called by the onFieldChange event on the current Field
*/
Tooltip.prototype.fieldChanged = function(ev) {
this.requisition.setAssignment(this.assignment, ev.conversion.arg);
var options = { argUpdate: true, matchPadding: true };
this.requisition.setAssignment(this.assignment, ev.conversion.arg, options);

var isError = ev.conversion.message != null && ev.conversion.message !== '';
this.focusManager.setError(isError);
Expand Down
1 change: 0 additions & 1 deletion lib/gclitest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ define(function(require, exports, module) {
exports.runAsync(options, function() {
console.log('Finished running unit tests.');
window.testCommands();
console.log('Test complete');
});
}, 10);

Expand Down

0 comments on commit 0f8e268

Please sign in to comment.