diff --git a/common/content/commands.js b/common/content/commands.js index 7cb620d6..ef1be527 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -784,12 +784,14 @@ const Commands = Module("commands", { str.replace(/\s*".*$/, ""); // 0 - count, 1 - cmd, 2 - special, 3 - args - let matches = str.match(/^([:\s]*(\d+|%)?([a-zA-Z]+|!)(!)?\s*)(.*?)?$/); + let matches = str.match(/^([:\s]*(\d+|%)?([a-zA-Z]+|!)(!)?(\s*))(.*?)?$/); //var matches = str.match(/^:*(\d+|%)?([a-zA-Z]+|!)(!)?(?:\s*(.*?)\s*)?$/); if (!matches) return [null, null, null, null]; - let [, spec, count, cmd, special, args] = matches; + let [, spec, count, cmd, special, space, args] = matches; + if (/\w/.test(cmd) && args && !space) + args = null; // parse count if (count) @@ -811,7 +813,7 @@ const Commands = Module("commands", { var context = complete.fork("args", len); } - if (command && /\w[!\s]/.test(str)) + if (command && (!complete || /\w[!\s]/.test(str))) args = command.parseArgs(args, context, { count: count, bang: bang }); else args = commands.parseArgs(args, { extra: { count: count, bang: bang } }); @@ -826,13 +828,16 @@ const Commands = Module("commands", { _subCommands: function (command) { let commands = [command]; while (command = commands.shift()) - for (let [command, args] in this.parseCommands(command)) { - if (command) { - yield [command, args]; - if (command.subCommand && args[command.subCommand]) - commands.push(args[command.subCommand]); + try { + for (let [command, args] in this.parseCommands(command)) { + if (command) { + yield [command, args]; + if (command.subCommand && args[command.subCommand]) + commands.push(args[command.subCommand]); + } } } + catch (e) {} }, /** @property */ @@ -953,7 +958,7 @@ const Commands = Module("commands", { let cmdContext = context.fork(command.name, prefix.length); try { if (!cmdContext.waitingForTab) { - if (!args.completeOpt && command.completer) { + if (!args.completeOpt && command.completer && args.completeStart != null) { cmdContext.advance(args.completeStart); cmdContext.quote = args.quote; cmdContext.filter = args.completeFilter; diff --git a/common/content/completion.js b/common/content/completion.js index 87f58cbc..a741302c 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -60,7 +60,7 @@ const CompletionContext = Class("CompletionContext", { self.__defineGetter__("value", function () this.top.value); self.offset = parent.offset; - self.advance(offset); + self.advance(offset || 0); /** * @property {boolean} Specifies that this context is not finished @@ -449,9 +449,9 @@ const CompletionContext = Class("CompletionContext", { this.cache.constructed = items.map(function (item) Object.create(proto, { item: { value: item, enumerable: true } })); // Filters - let filtered = this.filterFunc(this.cache.constructed); - if (this.maxItems) - filtered = filtered.slice(0, this.maxItems); + let filtered = this.filterFunc(this.cache.constructed); + if (this.maxItems) + filtered = filtered.slice(0, this.maxItems); // Sorting if (this.sortResults && this.compare)