From b2fad97cbac9df918e44e5edf2e617bca7cea8a4 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 11 Oct 2017 20:44:09 +0900 Subject: fix word splitter in completion --- src/shared/commands.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/shared/commands.js b/src/shared/commands.js index 32007bd..61044ec 100644 --- a/src/shared/commands.js +++ b/src/shared/commands.js @@ -111,22 +111,34 @@ const doCommand = (line, settings) => { throw new Error(name + ' command is not defined'); }; -const getCompletions = (command, keywords, settings) => { - switch (command) { +const getCompletions = (line, settings) => { + let typedWords = line.trim().split(/ +/); + let typing = ''; + if (!line.endsWith(' ')) { + typing = typedWords.pop(); + } + + if (typedWords.length === 0) { + return Promise.resolve([]); + } + let name = typedWords.shift(); + let keywords = typedWords.concat(typing).join(' '); + + switch (name) { case 'o': case 'open': case 't': case 'tabopen': case 'w': case 'winopen': - return getOpenCompletions(command, keywords, settings.search); + return getOpenCompletions(name, keywords, settings.search); case 'b': case 'buffer': return tabs.getCompletions(keywords).then((gotTabs) => { let items = gotTabs.map((tab) => { return { caption: tab.title, - content: command + ' ' + tab.title, + content: name + ' ' + tab.title, url: tab.url, icon: tab.favIconUrl }; @@ -147,9 +159,7 @@ const exec = (line, settings) => { }; const complete = (line, settings) => { - let command = line.split(' ', 1)[0]; - let keywords = line.replace(command + ' ', ''); - return getCompletions(command, keywords, settings); + return getCompletions(line, settings); }; export { exec, complete }; -- cgit v1.2.3