aboutsummaryrefslogtreecommitdiff
path: root/src/console
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-03-28 21:35:06 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2020-03-28 21:43:40 +0900
commitea63c5f78b4c985e9d6dd106afe4f97bfeedbcd0 (patch)
treef0accb862f9f3b75c8c86f78361e2acab46f11ef /src/console
parenta8d78f1286fb3fe456a786b2c0e534d212835560 (diff)
Complete tabs by the completion packages
Diffstat (limited to 'src/console')
-rw-r--r--src/console/actions/console.ts27
-rw-r--r--src/console/clients/CompletionClient.ts20
-rw-r--r--src/console/components/Console.tsx15
3 files changed, 59 insertions, 3 deletions
diff --git a/src/console/actions/console.ts b/src/console/actions/console.ts
index f1db941..603a98d 100644
--- a/src/console/actions/console.ts
+++ b/src/console/actions/console.ts
@@ -1,9 +1,10 @@
import * as messages from '../../shared/messages';
import * as actions from './index';
-import { Command } from "../../shared/Command";
+import {Command} from "../../shared/Command";
import CompletionClient from "../clients/CompletionClient";
import CompletionType from "../../shared/CompletionType";
import Completions from "../Completions";
+import TabFlag from "../../shared/TabFlag";
const completionClient = new CompletionClient();
@@ -155,6 +156,28 @@ const getOpenCompletions = async(
};
};
+const getTabCompletions = async (
+ original: string, command: Command, query: string, excludePinned: boolean,
+): Promise<actions.SetCompletionsAction> => {
+ const items = await completionClient.requestTabs(query, excludePinned);
+ const completions = [{
+ name: 'Buffers',
+ items: items.map(item => ({
+ content: command + ' ' + item.url,
+ caption: `${item.index}: ${item.flag != TabFlag.None ? item.flag : ' ' } ${item.title}`,
+ url: item.url,
+ icon: item.faviconUrl,
+ })),
+ }];
+ return {
+ type: actions.CONSOLE_SET_COMPLETIONS,
+ completions,
+ completionSource: original,
+ }
+};
+
+
+
const getCompletions = async(text: string): Promise<actions.SetCompletionsAction> => {
const completions = await browser.runtime.sendMessage({
type: messages.CONSOLE_QUERY_COMPLETIONS,
@@ -181,6 +204,6 @@ const completionPrev = (): actions.CompletionPrevAction => {
export {
hide, showCommand, showFind, showError, showInfo, hideCommand, setConsoleText, enterCommand, enterFind,
- getCompletions, getCommandCompletions, getOpenCompletions,
+ getCompletions, getCommandCompletions, getOpenCompletions, getTabCompletions,
completionNext, completionPrev,
};
diff --git a/src/console/clients/CompletionClient.ts b/src/console/clients/CompletionClient.ts
index d5f9b01..19b4d99 100644
--- a/src/console/clients/CompletionClient.ts
+++ b/src/console/clients/CompletionClient.ts
@@ -2,9 +2,10 @@ import * as messages from "../../shared/messages";
import {
ConsoleGetCompletionTypesResponse,
ConsoleRequestBookmarksResponse,
- ConsoleRequestHistoryResponse, ConsoleRequestSearchEnginesResponse
+ ConsoleRequestHistoryResponse, ConsoleRequestSearchEnginesResponse, ConsoleRequesttabsResponse
} from "../../shared/messages";
import CompletionType from "../../shared/CompletionType";
+import TabFlag from "../../shared/TabFlag";
export type SearchEngines = {
title: string
@@ -20,6 +21,14 @@ export type HistoryItem = {
url: string
}
+export type TabItem = {
+ index: number
+ flag: TabFlag
+ title: string
+ url: string
+ faviconUrl?: string
+}
+
export default class CompletionClient {
async getCompletionTypes(): Promise<CompletionType[]> {
const resp = await browser.runtime.sendMessage({
@@ -51,4 +60,13 @@ export default class CompletionClient {
}) as ConsoleRequestHistoryResponse;
return resp;
}
+
+ async requestTabs(query: string, excludePinned: boolean): Promise<TabItem[]> {
+ const resp = await browser.runtime.sendMessage({
+ type: messages.CONSOLE_REQUEST_TABS,
+ query,
+ excludePinned,
+ }) as ConsoleRequesttabsResponse;
+ return resp;
+ }
}
diff --git a/src/console/components/Console.tsx b/src/console/components/Console.tsx
index 7be073e..c1709cd 100644
--- a/src/console/components/Console.tsx
+++ b/src/console/components/Console.tsx
@@ -171,6 +171,21 @@ class Console extends React.Component<Props> {
case Command.WindowOpen:
this.props.dispatch(consoleActions.getOpenCompletions(this.props.completionTypes, text, cmd.command, cmd.args));
break;
+ case Command.Buffer:
+ this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, false));
+ break;
+ case Command.BufferDelete:
+ this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, true));
+ break;
+ case Command.BufferDeleteForce:
+ this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, false));
+ break;
+ case Command.BuffersDelete:
+ this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, true));
+ break;
+ case Command.BuffersDeleteForce:
+ this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, false));
+ break;
default:
this.props.dispatch(consoleActions.getCompletions(text));
}