mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Adding settings to control which schemes simple browser is enabled for
Also adds a setting to enable/disable the focus lock indicator
This commit is contained in:
parent
ba67d1bea4
commit
2fed7ba374
|
@ -155,6 +155,11 @@ window.addEventListener('message', e => {
|
|||
iframe.focus();
|
||||
break;
|
||||
}
|
||||
case 'didChangeFocusLockIndicatorEnabled':
|
||||
{
|
||||
toggleFocusLockIndicatorEnabled(e.data.enabled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
events_1.onceDocumentLoaded(() => {
|
||||
|
@ -189,10 +194,14 @@ events_1.onceDocumentLoaded(() => {
|
|||
iframe.src = input.value;
|
||||
});
|
||||
navigateTo(settings.url);
|
||||
toggleFocusLockIndicatorEnabled(settings.focusLockIndicatorEnabled);
|
||||
function navigateTo(url) {
|
||||
iframe.src = url;
|
||||
}
|
||||
});
|
||||
function toggleFocusLockIndicatorEnabled(enabled) {
|
||||
document.body.classList.toggle('enable-focus-lock-indicator', enabled);
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -110,6 +110,6 @@ iframe {
|
|||
pointer-events: none;
|
||||
}
|
||||
|
||||
.iframe-focused .iframe-focused-alert {
|
||||
.iframe-focused.enable-focus-lock-indicator .iframe-focused-alert {
|
||||
display: block;
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
"license": "MIT",
|
||||
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
|
||||
"engines": {
|
||||
"vscode": "^1.50.0"
|
||||
"vscode": "^1.53.0"
|
||||
},
|
||||
"main": "./out/extension",
|
||||
"browser": "./dist/browser/extension",
|
||||
"categories": [
|
||||
"Programming Languages"
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:simpleBrowser.show",
|
||||
|
@ -33,11 +33,26 @@
|
|||
{
|
||||
"title": "Simple Browser",
|
||||
"properties": {
|
||||
"simpleBrowser.focusLockIndicator.enabled": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"title": "Focus Lock Indicator Enabled",
|
||||
"description": "%configuration.focusLockIndicator.enabled.description%"
|
||||
},
|
||||
"simpleBrowser.opener.enabled": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"title": "Opener Enabled",
|
||||
"description": "(Experimental) Enables opening http and https urls using the built-in seper browser"
|
||||
"description": "%configuration.opener.enabled.description%"
|
||||
},
|
||||
"simpleBrowser.opener.enabledHosts": {
|
||||
"type": "array",
|
||||
"title": "Opener Enabled Hosts",
|
||||
"markdownDescription": "%configuration.opener.enabledHosts.description%",
|
||||
"default": [
|
||||
"localhost",
|
||||
"127.0.0.1"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,7 @@
|
|||
{
|
||||
"displayName": "Markdown Language Features",
|
||||
"description": "Provides rich language support for Markdown.",
|
||||
"markdown.preview.breaks.desc": "Sets how line-breaks are rendered in the markdown preview. Setting it to 'true' creates a <br> for newlines inside paragraphs.",
|
||||
"markdown.preview.linkify": "Enable or disable conversion of URL-like text to links in the markdown preview.",
|
||||
"markdown.preview.doubleClickToSwitchToEditor.desc": "Double click in the markdown preview to switch to the editor.",
|
||||
"markdown.preview.fontFamily.desc": "Controls the font family used in the markdown preview.",
|
||||
"markdown.preview.fontSize.desc": "Controls the font size in pixels used in the markdown preview.",
|
||||
"markdown.preview.lineHeight.desc": "Controls the line height used in the markdown preview. This number is relative to the font size.",
|
||||
"markdown.preview.markEditorSelection.desc": "Mark the current editor selection in the markdown preview.",
|
||||
"markdown.preview.scrollEditorWithPreview.desc": "When a markdown preview is scrolled, update the view of the editor.",
|
||||
"markdown.preview.scrollPreviewWithEditor.desc": "When a markdown editor is scrolled, update the view of the preview.",
|
||||
"markdown.preview.title": "Open Preview",
|
||||
"markdown.previewSide.title": "Open Preview to the Side",
|
||||
"markdown.showLockedPreviewToSide.title": "Open Locked Preview to the Side",
|
||||
"markdown.showSource.title": "Show Source",
|
||||
"markdown.styles.dec": "A list of URLs or local paths to CSS style sheets to use from the markdown preview. Relative paths are interpreted relative to the folder open in the explorer. If there is no open folder, they are interpreted relative to the location of the markdown file. All '\\' need to be written as '\\\\'.",
|
||||
"markdown.showPreviewSecuritySelector.title": "Change Preview Security Settings",
|
||||
"markdown.trace.desc": "Enable debug logging for the markdown extension.",
|
||||
"markdown.preview.refresh.title": "Refresh Preview",
|
||||
"markdown.preview.toggleLock.title": "Toggle Preview Locking",
|
||||
"configuration.markdown.preview.openMarkdownLinks.description": "Controls how links to other markdown files in the markdown preview should be opened.",
|
||||
"configuration.markdown.preview.openMarkdownLinks.inEditor": "Try to open links in the editor",
|
||||
"configuration.markdown.preview.openMarkdownLinks.inPreview": "Try to open links in the markdown preview",
|
||||
"configuration.markdown.links.openLocation.description": "Controls where links in markdown files should be opened.",
|
||||
"configuration.markdown.links.openLocation.currentGroup": "Open links in the active editor group.",
|
||||
"configuration.markdown.links.openLocation.beside": "Open links beside the active editor."
|
||||
"displayName": "Simple Browser",
|
||||
"description": "A very basic built-in webview for displaying web content.",
|
||||
"configuration.focusLockIndicator.enabled.description": "Enable/disable ",
|
||||
"configuration.opener.enabled.description": "(Experimental) Enables using the built-in simple browser when opening http and https urls.",
|
||||
"configuration.opener.enabledHosts.description": "Lists of hosts to open in the simple browser. For example: `localhost`."
|
||||
}
|
||||
|
|
|
@ -37,6 +37,11 @@ window.addEventListener('message', e => {
|
|||
iframe.focus();
|
||||
break;
|
||||
}
|
||||
case 'didChangeFocusLockIndicatorEnabled':
|
||||
{
|
||||
toggleFocusLockIndicatorEnabled(e.data.enabled);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -79,8 +84,14 @@ onceDocumentLoaded(() => {
|
|||
});
|
||||
|
||||
navigateTo(settings.url);
|
||||
toggleFocusLockIndicatorEnabled(settings.focusLockIndicatorEnabled);
|
||||
|
||||
function navigateTo(url: string): void {
|
||||
iframe.src = url;
|
||||
}
|
||||
});
|
||||
|
||||
function toggleFocusLockIndicatorEnabled(enabled: boolean) {
|
||||
document.body.classList.toggle('enable-focus-lock-indicator', enabled);
|
||||
}
|
||||
|
||||
|
|
42
extensions/simple-browser/src/dispose.ts
Normal file
42
extensions/simple-browser/src/dispose.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export function disposeAll(disposables: vscode.Disposable[]) {
|
||||
while (disposables.length) {
|
||||
const item = disposables.pop();
|
||||
if (item) {
|
||||
item.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class Disposable {
|
||||
private _isDisposed = false;
|
||||
|
||||
protected _disposables: vscode.Disposable[] = [];
|
||||
|
||||
public dispose(): any {
|
||||
if (this._isDisposed) {
|
||||
return;
|
||||
}
|
||||
this._isDisposed = true;
|
||||
disposeAll(this._disposables);
|
||||
}
|
||||
|
||||
protected _register<T extends vscode.Disposable>(value: T): T {
|
||||
if (this._isDisposed) {
|
||||
value.dispose();
|
||||
} else {
|
||||
this._disposables.push(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
protected get isDisposed() {
|
||||
return this._isDisposed;
|
||||
}
|
||||
}
|
|
@ -3,13 +3,14 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { URL } from 'url';
|
||||
import * as vscode from 'vscode';
|
||||
import { SimpleBrowserManager } from './simpleBrowserManager';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { SimpleBrowserManager } from './simpleBrowserManager';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
const openCommand = 'simpleBrowser.open';
|
||||
const openApiCommand = 'simpleBrowser.api.open';
|
||||
const showCommand = 'simpleBrowser.show';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
|
@ -30,7 +31,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
}
|
||||
}));
|
||||
|
||||
context.subscriptions.push(vscode.commands.registerCommand(openCommand, (url: vscode.Uri) => {
|
||||
context.subscriptions.push(vscode.commands.registerCommand(openApiCommand, (url: vscode.Uri) => {
|
||||
manager.show(url.toString());
|
||||
}));
|
||||
|
||||
|
@ -41,9 +42,22 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const enabledHosts = configuration.get<string[]>('opener.enabledHosts', [
|
||||
'localhost',
|
||||
'127.0.0.1'
|
||||
]);
|
||||
try {
|
||||
const url = new URL(uri.toString());
|
||||
if (!enabledHosts.includes(url.hostname)) {
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
title: localize('openTitle', "Open in simple browser"),
|
||||
command: openCommand,
|
||||
command: openApiCommand,
|
||||
arguments: [uri]
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,31 +5,34 @@
|
|||
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { Disposable } from './dispose';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export class SimpleBrowserView {
|
||||
export class SimpleBrowserView extends Disposable {
|
||||
|
||||
public static readonly viewType = 'simpleBrowser.view';
|
||||
private static readonly title = localize('view.title', "Simple Browser");
|
||||
|
||||
private readonly _webviewPanel: vscode.WebviewPanel;
|
||||
|
||||
private readonly _onDidDispose = new vscode.EventEmitter<void>();
|
||||
private readonly _onDidDispose = this._register(new vscode.EventEmitter<void>());
|
||||
public readonly onDispose = this._onDidDispose.event;
|
||||
|
||||
constructor(
|
||||
private readonly extensionUri: vscode.Uri,
|
||||
url: string,
|
||||
) {
|
||||
this._webviewPanel = vscode.window.createWebviewPanel(SimpleBrowserView.viewType, SimpleBrowserView.title, {
|
||||
super();
|
||||
|
||||
this._webviewPanel = this._register(vscode.window.createWebviewPanel(SimpleBrowserView.viewType, SimpleBrowserView.title, {
|
||||
viewColumn: vscode.ViewColumn.Active,
|
||||
}, {
|
||||
enableScripts: true,
|
||||
retainContextWhenHidden: true,
|
||||
});
|
||||
}));
|
||||
|
||||
this._webviewPanel.webview.onDidReceiveMessage(e => {
|
||||
this._register(this._webviewPanel.webview.onDidReceiveMessage(e => {
|
||||
switch (e.type) {
|
||||
case 'openExternal':
|
||||
try {
|
||||
|
@ -40,18 +43,28 @@ export class SimpleBrowserView {
|
|||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
this._webviewPanel.onDidDispose(() => {
|
||||
this._register(this._webviewPanel.onDidDispose(() => {
|
||||
this.dispose();
|
||||
});
|
||||
}));
|
||||
|
||||
this._register(vscode.workspace.onDidChangeConfiguration(e => {
|
||||
if (e.affectsConfiguration('simpleBrowser.focusLockIndicator.enabled')) {
|
||||
const configuration = vscode.workspace.getConfiguration('simpleBrowser');
|
||||
this._webviewPanel.webview.postMessage({
|
||||
type: 'didChangeFocusLockIndicatorEnabled',
|
||||
focusLockEnabled: configuration.get<boolean>('focusLockIndicator.enabled', true)
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
this.show(url);
|
||||
}
|
||||
|
||||
public dispose() {
|
||||
this._onDidDispose.fire();
|
||||
this._webviewPanel.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public show(url: string) {
|
||||
|
@ -60,6 +73,8 @@ export class SimpleBrowserView {
|
|||
}
|
||||
|
||||
private getHtml(url: string) {
|
||||
const configuration = vscode.workspace.getConfiguration('simpleBrowser');
|
||||
|
||||
const nonce = new Date().getTime() + '' + new Date().getMilliseconds();
|
||||
|
||||
const mainJs = this.extensionResourceUrl('media', 'index.js');
|
||||
|
@ -82,6 +97,7 @@ export class SimpleBrowserView {
|
|||
|
||||
<meta id="simple-browser-settings" data-settings="${escapeAttribute(JSON.stringify({
|
||||
url: url,
|
||||
focusLockEnabled: configuration.get<boolean>('focusLockIndicator.enabled', true)
|
||||
}))}">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="${mainCss}">
|
||||
|
|
Loading…
Reference in a new issue