A fork of https://github.com/ueokande/vim-vixen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.8 KiB
100 lines
2.8 KiB
5 years ago
|
import CompletionsUseCase from '../usecases/CompletionsUseCase';
|
||
|
import CommandUseCase from '../usecases/CommandUseCase';
|
||
|
import Completions from '../domains/Completions';
|
||
6 years ago
|
|
||
6 years ago
|
const trimStart = (str) => {
|
||
|
// NOTE String.trimStart is available on Firefox 61
|
||
|
return str.replace(/^\s+/, '');
|
||
|
};
|
||
|
|
||
6 years ago
|
export default class CommandController {
|
||
|
constructor() {
|
||
5 years ago
|
this.completionsUseCase = new CompletionsUseCase();
|
||
|
this.commandIndicator = new CommandUseCase();
|
||
6 years ago
|
}
|
||
|
|
||
|
getCompletions(line) {
|
||
6 years ago
|
let trimmed = trimStart(line);
|
||
6 years ago
|
let words = trimmed.split(/ +/);
|
||
|
let name = words[0];
|
||
|
if (words.length === 1) {
|
||
5 years ago
|
return this.completionsUseCase.queryConsoleCommand(name);
|
||
6 years ago
|
}
|
||
6 years ago
|
let keywords = trimStart(trimmed.slice(name.length));
|
||
6 years ago
|
switch (words[0]) {
|
||
|
case 'o':
|
||
|
case 'open':
|
||
|
case 't':
|
||
|
case 'tabopen':
|
||
|
case 'w':
|
||
|
case 'winopen':
|
||
5 years ago
|
return this.completionsUseCase.queryOpen(name, keywords);
|
||
6 years ago
|
case 'b':
|
||
|
case 'buffer':
|
||
5 years ago
|
return this.completionsUseCase.queryBuffer(name, keywords);
|
||
6 years ago
|
case 'bd':
|
||
|
case 'bdel':
|
||
|
case 'bdelete':
|
||
|
case 'bdeletes':
|
||
5 years ago
|
return this.completionsUseCase.queryBdelete(name, keywords);
|
||
6 years ago
|
case 'bd!':
|
||
|
case 'bdel!':
|
||
|
case 'bdelete!':
|
||
|
case 'bdeletes!':
|
||
5 years ago
|
return this.completionsUseCase.queryBdeleteForce(name, keywords);
|
||
6 years ago
|
case 'set':
|
||
5 years ago
|
return this.completionsUseCase.querySet(name, keywords);
|
||
6 years ago
|
}
|
||
|
return Promise.resolve(Completions.empty());
|
||
|
}
|
||
|
|
||
|
// eslint-disable-next-line complexity
|
||
|
exec(line) {
|
||
6 years ago
|
let trimmed = trimStart(line);
|
||
6 years ago
|
let words = trimmed.split(/ +/);
|
||
|
let name = words[0];
|
||
6 years ago
|
if (words[0].length === 0) {
|
||
|
return Promise.resolve();
|
||
|
}
|
||
|
|
||
6 years ago
|
let keywords = trimStart(trimmed.slice(name.length));
|
||
6 years ago
|
switch (words[0]) {
|
||
|
case 'o':
|
||
|
case 'open':
|
||
|
return this.commandIndicator.open(keywords);
|
||
|
case 't':
|
||
|
case 'tabopen':
|
||
|
return this.commandIndicator.tabopen(keywords);
|
||
|
case 'w':
|
||
|
case 'winopen':
|
||
|
return this.commandIndicator.winopen(keywords);
|
||
|
case 'b':
|
||
|
case 'buffer':
|
||
|
return this.commandIndicator.buffer(keywords);
|
||
|
case 'bd':
|
||
|
case 'bdel':
|
||
|
case 'bdelete':
|
||
|
return this.commandIndicator.bdelete(false, keywords);
|
||
|
case 'bd!':
|
||
|
case 'bdel!':
|
||
|
case 'bdelete!':
|
||
|
return this.commandIndicator.bdelete(true, keywords);
|
||
|
case 'bdeletes':
|
||
|
return this.commandIndicator.bdeletes(false, keywords);
|
||
|
case 'bdeletes!':
|
||
|
return this.commandIndicator.bdeletes(true, keywords);
|
||
|
case 'addbookmark':
|
||
|
return this.commandIndicator.addbookmark(keywords);
|
||
|
case 'q':
|
||
|
case 'quit':
|
||
|
return this.commandIndicator.quit();
|
||
|
case 'qa':
|
||
|
case 'quitall':
|
||
|
return this.commandIndicator.quitAll();
|
||
|
case 'set':
|
||
|
return this.commandIndicator.set(keywords);
|
||
|
}
|
||
6 years ago
|
throw new Error(words[0] + ' command is not defined');
|
||
6 years ago
|
}
|
||
|
}
|