Skip to content

Commit

Permalink
Allow for passing in some parsed data instead of the cmd line to be p…
Browse files Browse the repository at this point in the history
…arsed
  • Loading branch information
CoderPuppy committed Apr 19, 2012
1 parent 060b382 commit ae3a522
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/autocomplete.js
Expand Up @@ -17,9 +17,15 @@ define(['require', 'exports', './commandParser', './argument'], function(require
AutoCompleter.prototype.autoComplete = function autoComplete(cmdLine, position, terminal) {
var cmdName, args, parsed;

if(typeof(position) == 'number') position = this.positionFromCursorPos(cmdLine, position);
if(typeof(cmdLine) == 'object' && typeof(cmdLine.length) != 'undefined') {
parsed = cmdLine;
cmdLine = parsed.text;
} else {
parsed = this.parse(cmdLine);
}

if(typeof(position) == 'number') position = this.positionFromCursorPos(parsed, position);

parsed = this.parse(cmdLine);
args = parsed[position && position.length > 0 ? position[0] : parsed.length - 1].args;

if(args.length <= 1 && args[0] && args[0].length <= 0) {
Expand Down Expand Up @@ -101,7 +107,7 @@ define(['require', 'exports', './commandParser', './argument'], function(require
};

AutoCompleter.prototype.positionFromCursorPos = function positionFromCursorPos(value, cursor) {
var parsed = this.parse(value, this.findPosCmdParser), args;
var parsed = ( typeof(value) == 'object' && typeof(value.length) != 'undefined' ? value : this.parse(value, this.findPosCmdParser) ), args;

for(var i = 0; i < parsed.length; i++) {
if(parsed[i].begin <= cursor && parsed[i].end >= cursor) {
Expand Down

0 comments on commit ae3a522

Please sign in to comment.