Permalink
Browse files

Merge branch 'menuclick-788215'

  • Loading branch information...
2 parents a2936b0 + 79b8403 commit 440410d1f6c996a4587e7274a6d6eae688842afc @joewalker committed Oct 13, 2012
View
@@ -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
@@ -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;
}
@@ -608,26 +608,22 @@ Requisition.prototype.getAssignments = function(includeCommand) {
};
/**
- * 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
@@ -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];
}
}
@@ -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);
};
@@ -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
@@ -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 });
}
};
@@ -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 });
}
};
@@ -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 });
}
};
@@ -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;
}
@@ -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();
@@ -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;
}
}
@@ -1562,7 +1568,7 @@ Requisition.prototype._assign = function(args) {
arrayArg.addArgument(arg);
}
else {
- this._setAssignment(assignment, arg, true);
+ this.setAssignment(assignment, arg);
}
}
else {
@@ -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;
}
@@ -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];
@@ -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);
}
}
}
@@ -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
View
@@ -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);
@@ -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) {
View
@@ -91,12 +91,11 @@ Menu.prototype.destroy = function() {
* @param ev The click event from the browser
*/
Menu.prototype.onItemClickInternal = function(ev) {
- var name = ev.currentTarget.querySelector('.gcli-menu-name').innerHTML;
+ var name = ev.currentTarget.querySelector('.gcli-menu-name').textContent;
var arg = new Argument(name);
arg.suffix = ' ';
- var conversion = this.type.parse(arg);
- this.onItemClick({ conversion: conversion });
+ this.onItemClick({ arg: arg });
};
/**
@@ -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));
}
@@ -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;
}
@@ -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;
};
@@ -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) {
View
@@ -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);
View
@@ -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);

0 comments on commit 440410d

Please sign in to comment.