From 830065c4c6e112fb0302b84958c8e20fb2688b6f Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Sun, 14 Oct 2018 00:28:00 +0100 Subject: [PATCH] Revert "Add FileSystem completion" This partially reverts commit 698fc6a and 25af877. The completion was causing breaking tabopen and other completions for people with outdated native messengers. --- src/background/native_background.ts | 14 ++---- src/commandline_frame.ts | 2 - src/completions/FileSystem.ts | 73 ----------------------------- src/lib/messaging.ts | 1 - 4 files changed, 3 insertions(+), 87 deletions(-) delete mode 100644 src/completions/FileSystem.ts diff --git a/src/background/native_background.ts b/src/background/native_background.ts index 9b04cb59..9d1775bd 100644 --- a/src/background/native_background.ts +++ b/src/background/native_background.ts @@ -2,7 +2,6 @@ * Background functions for the native messenger interface */ -import * as Messaging from "@src/lib/messaging" import * as semverCompare from "semver-compare" import * as config from "@src/lib/config" import { browserBg } from "@src/lib/webext" @@ -17,7 +16,6 @@ type MessageCommand = | "read" | "write" | "temp" - | "list_dir" | "mkdir" | "move" | "eval" @@ -56,10 +54,11 @@ async function sendNativeMsg( } } -export async function getrcpath(): Promise { +export async function getrcpath(): Promise { const res = await sendNativeMsg("getconfigpath", {}) - if (res.code != 0) throw new Error("getrcpath error: " + res.code) + if (res.code != 0) + throw new Error("getrcpath error: " + res.code) return res.content } @@ -261,10 +260,6 @@ export async function move(from: string, to: string) { return sendNativeMsg("move", { from, to }) } -export async function listDir(dir: string) { - return sendNativeMsg("list_dir", { path: dir }) -} - export async function winFirefoxRestart( profiledir: string, browsercmd: string, @@ -587,6 +582,3 @@ export async function writePref(name: string, value: any) { write(file, text.replace(substr, `pref("${name}", ${value})`)) } } - -import * as SELF from "@src/background/native_background" -Messaging.addListener("native_background", Messaging.attributeCaller(SELF)) diff --git a/src/commandline_frame.ts b/src/commandline_frame.ts index 2b35869c..b52de358 100644 --- a/src/commandline_frame.ts +++ b/src/commandline_frame.ts @@ -8,7 +8,6 @@ import { BufferAllCompletionSource } from "@src/completions/BufferAll" import { BufferCompletionSource } from "@src/completions/Buffer" import { BmarkCompletionSource } from "@src/completions/Bmark" import { ExcmdCompletionSource } from "@src/completions/Excmd" -import { FileSystemCompletionSource } from "@src/completions/FileSystem" import { HelpCompletionSource } from "@src/completions/Help" import { HistoryCompletionSource } from "@src/completions/History" import { SettingsCompletionSource } from "@src/completions/Settings" @@ -67,7 +66,6 @@ function enableCompletions() { new BufferAllCompletionSource(completionsDiv), new BufferCompletionSource(completionsDiv), new ExcmdCompletionSource(completionsDiv), - new FileSystemCompletionSource(completionsDiv), new HelpCompletionSource(completionsDiv), new HistoryCompletionSource(completionsDiv), new SettingsCompletionSource(completionsDiv), diff --git a/src/completions/FileSystem.ts b/src/completions/FileSystem.ts deleted file mode 100644 index 637a3400..00000000 --- a/src/completions/FileSystem.ts +++ /dev/null @@ -1,73 +0,0 @@ -import * as Completions from "@src/completions" -import * as Messaging from "@src/lib/messaging" -import * as config from "@src/lib/config" - -class FileSystemCompletionOption extends Completions.CompletionOptionHTML - implements Completions.CompletionOptionFuse { - public fuseKeys = [] - - constructor(public value: string) { - super() - this.fuseKeys = [value] - this.html = html` - ${value} - ` - } -} - -export class FileSystemCompletionSource extends Completions.CompletionSourceFuse { - public options: FileSystemCompletionOption[] - - constructor(private _parent) { - super(["saveas", "source"], "FileSystemCompletionSource", "FileSystem") - - this._parent.appendChild(this.node) - } - - public async onInput(exstr) { - this.filter(exstr) - } - - public async filter(exstr: string) { - if (!exstr || exstr.indexOf(" ") == -1) { - this.state = "hidden" - return - } - - let [cmd, path] = this.splitOnPrefix(exstr) - if (!path) path = "." - - if (!["/", "$", "~", "."].find(s => path.startsWith(s))) { - // If the path doesn't start with a special character, it is relative to the native messenger, thus use "." as starting point - // Does this work on windows? - path = "./" + path - } - - // Update lastExstr because we modified the path and scoreOptions uses that in order to assign scores - this.lastExstr = cmd + path - - let req - try { - req = await Messaging.message("native_background", "listDir", [ - path, - ]) - } catch (e) { - // Failing silently because we can't nativegate (the user is typing stuff in the commandline) - this.state = "hidden" - return - } - - if (req.isDir) { - if (!path.endsWith(req.sep)) path += req.sep - } else { - path = path.substring(0, path.lastIndexOf("/") + 1) - } - - this.options = req.files.map( - p => new FileSystemCompletionOption(path + p), - ) - - this.state = "normal" - this.updateChain() - } -} diff --git a/src/lib/messaging.ts b/src/lib/messaging.ts index 98b4bbb6..9e96ef88 100644 --- a/src/lib/messaging.ts +++ b/src/lib/messaging.ts @@ -11,7 +11,6 @@ export type NonTabMessageType = | "commandline_background" | "controller_background" | "browser_proxy_background" - | "native_background" | "download_background" | "performance_background" export type MessageType = TabMessageType | NonTabMessageType