|
|
|
@ -5,12 +5,14 @@ import CommandDocs from '../domains/command-docs'; |
|
|
|
|
import CompletionRepository from '../repositories/completions'; |
|
|
|
|
import * as filters from './filters'; |
|
|
|
|
import SettingRepository from '../repositories/setting'; |
|
|
|
|
import TabPresenter from '../presenters/tab'; |
|
|
|
|
import * as properties from '../../shared/settings/properties'; |
|
|
|
|
|
|
|
|
|
const COMPLETION_ITEM_LIMIT = 10; |
|
|
|
|
|
|
|
|
|
export default class CompletionsInteractor { |
|
|
|
|
constructor() { |
|
|
|
|
this.tabPresenter = new TabPresenter(); |
|
|
|
|
this.completionRepository = new CompletionRepository(); |
|
|
|
|
this.settingRepository = new SettingRepository(); |
|
|
|
|
} |
|
|
|
@ -50,8 +52,48 @@ export default class CompletionsInteractor { |
|
|
|
|
return new Completions(groups); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
queryBuffer(name, keywords) { |
|
|
|
|
return this.queryTabs(name, false, keywords); |
|
|
|
|
// eslint-disable-next-line max-statements
|
|
|
|
|
async queryBuffer(name, keywords) { |
|
|
|
|
let lastId = await this.tabPresenter.getLastSelectedId(); |
|
|
|
|
let trimmed = keywords.trim(); |
|
|
|
|
let tabs = []; |
|
|
|
|
if (trimmed.length > 0 && !isNaN(trimmed)) { |
|
|
|
|
let all = await this.tabPresenter.getAll(); |
|
|
|
|
let index = parseInt(trimmed, 10) - 1; |
|
|
|
|
if (index >= 0 && index < all.length) { |
|
|
|
|
tabs = [all[index]]; |
|
|
|
|
} |
|
|
|
|
} else if (trimmed === '%') { |
|
|
|
|
let all = await this.tabPresenter.getAll(); |
|
|
|
|
let tab = all.find(t => t.active); |
|
|
|
|
tabs = [tab]; |
|
|
|
|
} else if (trimmed === '#') { |
|
|
|
|
if (typeof lastId !== 'undefined' && lastId !== null) { |
|
|
|
|
let all = await this.tabPresenter.getAll(); |
|
|
|
|
let tab = all.find(t => t.id === lastId); |
|
|
|
|
tabs = [tab]; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
tabs = await this.completionRepository.queryTabs(keywords, false); |
|
|
|
|
} |
|
|
|
|
const flag = (tab) => { |
|
|
|
|
if (tab.active) { |
|
|
|
|
return '%'; |
|
|
|
|
} else if (tab.id === lastId) { |
|
|
|
|
return '#'; |
|
|
|
|
} |
|
|
|
|
return ' '; |
|
|
|
|
}; |
|
|
|
|
let items = tabs.map(tab => new CompletionItem({ |
|
|
|
|
caption: tab.index + 1 + ': ' + flag(tab) + ' ' + tab.title, |
|
|
|
|
content: name + ' ' + tab.title, |
|
|
|
|
url: tab.url, |
|
|
|
|
icon: tab.favIconUrl |
|
|
|
|
})); |
|
|
|
|
if (items.length === 0) { |
|
|
|
|
return Promise.resolve(Completions.empty()); |
|
|
|
|
} |
|
|
|
|
return new Completions([new CompletionGroup('Buffers', items)]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
queryBdelete(name, keywords) { |
|
|
|
|