From ea63c5f78b4c985e9d6dd106afe4f97bfeedbcd0 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 28 Mar 2020 21:35:06 +0900 Subject: Complete tabs by the completion packages --- src/console/actions/console.ts | 27 +++++++++++++++++++++++++-- src/console/clients/CompletionClient.ts | 20 +++++++++++++++++++- src/console/components/Console.tsx | 15 +++++++++++++++ 3 files changed, 59 insertions(+), 3 deletions(-) (limited to 'src/console') 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 => { + 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 => { 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 { 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 { + 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 { 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)); } -- cgit v1.2.3