From b7b4b940ae76a7b75293b1cc611c2c7856e62173 Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Wed, 4 Oct 2017 21:35:52 +0100 Subject: [PATCH] Make commandline show only after : is pressed I have also attempted to make the commmand line hide when it is not in focus, but had no luck. --- src/commandline_content.ts | 18 ++++++++++++------ src/excmds_background.ts | 7 +++++++ src/excmds_content.ts | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/commandline_content.ts b/src/commandline_content.ts index ec1acd2a..54dbc3ba 100644 --- a/src/commandline_content.ts +++ b/src/commandline_content.ts @@ -10,10 +10,16 @@ */ // inject the commandline iframe into a content page -let clFrame = window.document.createElement("iframe") -clFrame.setAttribute("src", browser.extension.getURL("static/commandline.html")) -clFrame.setAttribute("style", "position: fixed; top: 0; left: 0; z-index: 10000; width: 100%; height: 36px; border: 0; padding: 0; margin: 0;"); -window.document.body.appendChild(clFrame) +export function showcommandline(){ + let clFrame = window.document.createElement("iframe") + clFrame.setAttribute("src", browser.extension.getURL("static/commandline.html")) + clFrame.setAttribute("style", "position: fixed; top: 0; left: 0; z-index: 10000; width: 100%; height: 36px; border: 0; padding: 0; margin: 0;"); + window.document.body.appendChild(clFrame) -/** Focus the commandline input */ -export let focus = ():void => clFrame.focus() + /** Focus the commandline input: not required **/ + // let focus = ():void => clFrame.focus() + // line below doesn't work + clFrame.addEventListener("blur",clFrame.remove) + // Why were we returning focus? It's a void, surely? + // return focus +} diff --git a/src/excmds_background.ts b/src/excmds_background.ts index f0e745f4..4e3f53fa 100644 --- a/src/excmds_background.ts +++ b/src/excmds_background.ts @@ -1,4 +1,5 @@ /** Conventional definition of modulo that never gives a -ve result. */ + Number.prototype.mod = function (n: number): number { return Math.abs(this % n) } @@ -89,6 +90,12 @@ export async function reload(n = 1, hard = false){ ) } +// Commandline function + +export function showcommandline(){ + messageActiveTab("showcommandline") +} + // TODO: address should default to some page to which we have access // and focus the location bar export async function tabopen(address?: string){ diff --git a/src/excmds_content.ts b/src/excmds_content.ts index b2a7c8a1..60dd6977 100644 --- a/src/excmds_content.ts +++ b/src/excmds_content.ts @@ -24,7 +24,7 @@ const commands = new Map([ window.history.go(n) }, function focuscmdline() { - CommandLineContent.focus() + CommandLineContent.showcommandline() } ].map((command):any => [command.name, command]))