diff --git a/src/background/controllers/completions.js b/src/background/controllers/completions.js index 613940f..c22ba83 100644 --- a/src/background/controllers/completions.js +++ b/src/background/controllers/completions.js @@ -13,6 +13,7 @@ export default class ContentMessageController { if (words.length === 1) { return this.completionsInteractor.queryConsoleCommand(name); } + let keywords = trimmed.slice(name.length).trimStart(); switch (words[0]) { case 'o': case 'open': @@ -20,22 +21,22 @@ export default class ContentMessageController { case 'tabopen': case 'w': case 'winopen': - break; + return this.completionsInteractor.queryOpen(name); case 'b': case 'buffer': - break; - case 'bd!': - case 'bdel!': - case 'bdelete!': - case 'bdeletes!': - break; + return this.completionsInteractor.queryBuffer(name, keywords); case 'bd': case 'bdel': case 'bdelete': case 'bdeletes': - break; + return this.completionsInteractor.queryBdelete(name, keywords); + case 'bd!': + case 'bdel!': + case 'bdelete!': + case 'bdeletes!': + return this.completionsInteractor.queryBdeleteForce(name, keywords); case 'set': - break; + return this.completionsInteractor.querySet(name, keywords); } return Promise.resolve(Completions.empty()); } diff --git a/src/background/repositories/completions.js b/src/background/repositories/completions.js new file mode 100644 index 0000000..30ede05 --- /dev/null +++ b/src/background/repositories/completions.js @@ -0,0 +1,11 @@ +export default class CompletionsRepository { + async queryTabs(keywords, excludePinned) { + let tabs = await browser.tabs.query({ currentWindow: true }); + return tabs.filter((t) => { + return t.url.toLowerCase().includes(keywords.toLowerCase()) || + t.title && t.title.toLowerCase().includes(keywords.toLowerCase()); + }).filter((t) => { + return !(excludePinned && t.pinned); + }); + } +} diff --git a/src/background/usecases/completions.js b/src/background/usecases/completions.js index fc1ff52..21049d2 100644 --- a/src/background/usecases/completions.js +++ b/src/background/usecases/completions.js @@ -22,19 +22,39 @@ export default class CompletionsInteractor { if (items.length === 0) { return Promise.resolve(Completions.empty()); } - return Promise.resolve(new Completions( - [new CompletionGroup('Console Command', items)] - )); + return Promise.resolve( + new Completions([new CompletionGroup('Console Command', items)]) + ); } - async queryBdeleteCommand(name, force, args) { - let tabs = await this.completionRepository.queryTabs(args); + queryOpen() { + return Promise.resolve(Completions.empty()); + } + + queryBuffer(name, keywords) { + return this.queryTabs(name, true, keywords); + } + + queryBdelete(name, keywords) { + return this.queryTabs(name, true, keywords); + } + + queryBdeleteForce(name, keywords) { + return this.queryTabs(name, false, keywords); + } + + querySet() { + return Promise.resolve(Completions.empty()); + } + + async queryTabs(name, excludePinned, args) { + let tabs = await this.completionRepository.queryTabs(args, excludePinned); let items = tabs.map(tab => new CompletionItem({ caption: tab.title, content: name + ' ' + tab.title, url: tab.url, icon: tab.favIconUrl })); - return [new CompletionGroup('Buffers', items)]; + return new Completions([new CompletionGroup('Buffers', items)]); } }