Complete console commands
This commit is contained in:
parent
067da88d06
commit
a28f6f916d
2 changed files with 36 additions and 16 deletions
|
@ -1,7 +1,19 @@
|
|||
import commandDocs from 'shared/commands/docs';
|
||||
import * as tabs from './tabs';
|
||||
import * as histories from './histories';
|
||||
import * as bookmarks from './bookmarks';
|
||||
|
||||
const completeCommands = (typing) => {
|
||||
let keys = Object.keys(commandDocs);
|
||||
return keys
|
||||
.filter(name => name.startsWith(typing))
|
||||
.map(name => ({
|
||||
caption: name,
|
||||
content: name,
|
||||
url: commandDocs[name],
|
||||
}));
|
||||
};
|
||||
|
||||
const getSearchCompletions = (command, keywords, searchConfig) => {
|
||||
let engineNames = Object.keys(searchConfig.engines);
|
||||
let engineItems = engineNames.filter(name => name.startsWith(keywords))
|
||||
|
@ -74,20 +86,21 @@ const getBufferCompletions = async(command, keywords, excludePinned) => {
|
|||
];
|
||||
};
|
||||
|
||||
const getCompletions = (line, settings) => {
|
||||
let typedWords = line.trim().split(/ +/);
|
||||
let typing = '';
|
||||
if (!line.endsWith(' ')) {
|
||||
typing = typedWords.pop();
|
||||
const complete = (line, settings) => {
|
||||
let trimmed = line.trimStart();
|
||||
let words = trimmed.split(/ +/);
|
||||
let name = words[0];
|
||||
if (words.length === 1) {
|
||||
return Promise.resolve([
|
||||
{
|
||||
name: 'Console Command',
|
||||
items: completeCommands(name),
|
||||
}
|
||||
]);
|
||||
}
|
||||
let keywords = trimmed.slice(name.length).trimStart();
|
||||
|
||||
if (typedWords.length === 0) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
let name = typedWords.shift();
|
||||
let keywords = typedWords.concat(typing).join(' ');
|
||||
|
||||
switch (name) {
|
||||
switch (words[0]) {
|
||||
case 'o':
|
||||
case 'open':
|
||||
case 't':
|
||||
|
@ -112,8 +125,4 @@ const getCompletions = (line, settings) => {
|
|||
return Promise.resolve([]);
|
||||
};
|
||||
|
||||
const complete = (line, settings) => {
|
||||
return getCompletions(line, settings);
|
||||
};
|
||||
|
||||
export { complete };
|
||||
|
|
11
src/shared/commands/docs.js
Normal file
11
src/shared/commands/docs.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
export default {
|
||||
set: 'Set a value of the property',
|
||||
open: 'Open a URL or search by keywords in current tab',
|
||||
tabopen: 'Open a URL or search by keywords in new tab',
|
||||
winopen: 'Open a URL or search by keywords in new window',
|
||||
buffer: 'Sekect tabs by matched keywords',
|
||||
bdelete: 'Close a certain tab matched by keywords',
|
||||
bdeletes: 'Close all tabs matched by keywords',
|
||||
quit: 'Close the current tab',
|
||||
quitall: 'Close all tabs',
|
||||
};
|
Reference in a new issue