aboutsummaryrefslogtreecommitdiff
path: root/src/console/actions/console.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-03-25 20:59:29 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2020-03-25 20:59:29 +0900
commit70b08f1025d3e00a016843669d61c56789bc0028 (patch)
treee1f99494016a0b13894f1e739f1ff87102c4fd13 /src/console/actions/console.ts
parent7d51364584e9081f71f4691a713bb737f7573a74 (diff)
Complete commands on the console script
Diffstat (limited to 'src/console/actions/console.ts')
-rw-r--r--src/console/actions/console.ts37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/console/actions/console.ts b/src/console/actions/console.ts
index f7fa7a2..cef04fe 100644
--- a/src/console/actions/console.ts
+++ b/src/console/actions/console.ts
@@ -1,5 +1,20 @@
import * as messages from '../../shared/messages';
import * as actions from './index';
+import { Command } from "../../shared/Command";
+
+const commandDocs = {
+ [Command.Set]: 'Set a value of the property',
+ [Command.Open]: 'Open a URL or search by keywords in current tab',
+ [Command.TabOpen]: 'Open a URL or search by keywords in new tab',
+ [Command.WindowOpen]: 'Open a URL or search by keywords in new window',
+ [Command.Buffer]: 'Select tabs by matched keywords',
+ [Command.BufferDelete]: 'Close a certain tab matched by keywords',
+ [Command.BuffersDelete]: 'Close all tabs matched by keywords',
+ [Command.Quit]: 'Close the current tab',
+ [Command.QuitAll]: 'Close all tabs',
+ [Command.AddBookmark]: 'Add current page to bookmarks',
+ [Command.Help]: 'Open Vim Vixen help in new tab',
+};
const hide = (): actions.ConsoleAction => {
return {
@@ -68,6 +83,26 @@ const setConsoleText = (consoleText: string): actions.ConsoleAction => {
};
};
+const getCommandCompletions = (text: string): actions.ConsoleAction => {
+ const items = Object.entries(commandDocs)
+ .filter(([name]) => name.startsWith(text.trimLeft()))
+ .map(([name, doc]) => ({
+ caption: name,
+ content: name,
+ url: doc,
+ }));
+ const completions = [{
+ name: "Console Command",
+ items,
+ }];
+ return {
+ type: actions.CONSOLE_SET_COMPLETIONS,
+ completions,
+ completionSource: text,
+ }
+};
+
+
const getCompletions = async(text: string): Promise<actions.ConsoleAction> => {
const completions = await browser.runtime.sendMessage({
type: messages.CONSOLE_QUERY_COMPLETIONS,
@@ -94,5 +129,5 @@ const completionPrev = (): actions.ConsoleAction => {
export {
hide, showCommand, showFind, showError, showInfo, hideCommand, setConsoleText,
- enterCommand, enterFind, getCompletions, completionNext, completionPrev,
+ enterCommand, enterFind, getCompletions, getCommandCompletions, completionNext, completionPrev,
};