提交 263e346c 编写于 作者: B Benjamin Pasero

Merge branch 'master' into ben/1.3.8

{
"name": "git",
"publisher": "vscode",
"displayName": "git",
"description": "Git",
"version": "0.0.1",
......
......@@ -9,13 +9,13 @@
* enables reusing existing code without migrating to a specific promise implementation. Still,
* we recommend the use of native promises which are available in VS Code.
*/
interface Thenable<R> {
interface Thenable<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
}
\ No newline at end of file
......@@ -189,53 +189,31 @@ export class FoldingController implements editorCommon.IEditorContribution {
return;
}
this.contentChangedScheduler = new RunOnceScheduler(() => {
let myToken = (++this.computeToken);
this.computeCollapsibleRegions().then(regions => {
if (myToken !== this.computeToken) {
return; // A new request was made in the meantime or the model was changed
}
this.applyRegions(regions);
});
}, 200);
this.cursorChangedScheduler = new RunOnceScheduler(() => {
this.revealCursor();
}, 200);
this.computeAndApplyCollapsibleRegions();
this.contentChangedScheduler = new RunOnceScheduler(() => this.computeAndApplyCollapsibleRegions(), 200);
this.cursorChangedScheduler = new RunOnceScheduler(() => this.revealCursor(), 200);
this.localToDispose.push(this.contentChangedScheduler);
this.localToDispose.push(this.cursorChangedScheduler);
this.localToDispose.push(this.editor.onDidChangeModelContent(() => {
this.contentChangedScheduler.schedule();
}));
this.localToDispose.push({
dispose: () => {
++this.computeToken;
this.editor.changeDecorations(changeAccessor => {
this.decorations.forEach(dec => dec.dispose(changeAccessor));
});
this.decorations = [];
this.editor.setHiddenAreas([]);
}
});
this.localToDispose.push(this.editor.onDidChangeModelContent(e => this.contentChangedScheduler.schedule()));
this.localToDispose.push(this.editor.onDidChangeCursorPosition(e => this.cursorChangedScheduler.schedule()));
this.localToDispose.push(this.editor.onMouseDown(e => this.onEditorMouseDown(e)));
this.localToDispose.push(this.editor.onMouseUp(e => this.onEditorMouseUp(e)));
this.localToDispose.push(this.editor.onDidChangeCursorPosition(e => {
this.cursorChangedScheduler.schedule();
}));
this.contentChangedScheduler.schedule();
this.localToDispose.push({ dispose: () => this.disposeDecorations() });
}
private computeCollapsibleRegions(): TPromise<IFoldingRange[]> {
private computeAndApplyCollapsibleRegions(): void {
let model = this.editor.getModel();
if (!model) {
return TPromise.as([]);
}
this.applyRegions(model ? computeRanges(model) : []);
}
let ranges = computeRanges(model);
return TPromise.as(ranges);
private disposeDecorations() {
this.editor.changeDecorations(changeAccessor => {
this.decorations.forEach(dec => dec.dispose(changeAccessor));
});
this.decorations = [];
this.editor.setHiddenAreas([]);
}
private revealCursor() {
......
......@@ -4203,13 +4203,13 @@ declare module 'vscode' {
* enables reusing existing code without migrating to a specific promise implementation. Still,
* we recommend the use of native promises which are available in VS Code.
*/
interface Thenable<R> {
interface Thenable<T> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
}
......@@ -4,11 +4,11 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import URI from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import URI from 'vs/base/common/uri';
import { Position as EditorPosition } from 'vs/platform/editor/common/editor';
import { HtmlInput } from '../common/htmlInput';
import { HtmlPreviewPart } from 'vs/workbench/parts/html/browser/htmlPreviewPart';
......@@ -17,6 +17,8 @@ import { EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/common/editor';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { isCommonCodeEditor, ICommonCodeEditor, IModel } from 'vs/editor/common/editorCommon';
import { HtmlZoneController } from './htmlEditorZone';
// --- Register Editor
(<IEditorRegistry>Registry.as(EditorExtensions.Editors)).registerEditor(new EditorDescriptor(HtmlPreviewPart.ID,
......@@ -27,6 +29,43 @@ import { IEditorGroupService } from 'vs/workbench/services/group/common/groupSer
// --- Register Commands
interface HtmlZoneParams {
editorPosition: EditorPosition;
lineNumber: number;
resource: URI;
}
let warn = true;
CommandsRegistry.registerCommand('_workbench.htmlZone', function (accessor: ServicesAccessor, params: HtmlZoneParams) {
if (warn) {
console.warn(`'_workbench.htmlZone' is an EXPERIMENTAL feature and therefore subject to CHANGE and REMOVAL without notice.`);
warn = false;
}
let codeEditor: ICommonCodeEditor;
for (const editor of accessor.get(IWorkbenchEditorService).getVisibleEditors()) {
if (editor.position === params.editorPosition) {
const control = editor.getControl();
if (isCommonCodeEditor(control)) {
codeEditor = control;
}
}
}
if (!codeEditor) {
console.warn('NO matching editor found');
return;
}
return accessor.get(IWorkbenchEditorService).resolveEditorModel({ resource: params.resource }).then(model => {
const contents = (<IModel>model.textEditorModel).getValue();
HtmlZoneController.getInstance(codeEditor).addZone(params.lineNumber, contents);
});
});
CommandsRegistry.registerCommand('_workbench.previewHtml', function (accessor: ServicesAccessor, resource: URI | string, position?: EditorPosition, label?: string) {
const uri = resource instanceof URI ? resource : URI.parse(resource);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IEditorContribution, ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { ICodeEditor, IViewZone } from 'vs/editor/browser/editorBrowser';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
import Webview from './webview';
class HtmlZone implements IViewZone {
zoneId: number;
private _domNode: HTMLElement;
private _webview: Webview;
private _disposables: IDisposable[] = [];
constructor(public lineNumber: number, public htmlContent: string) {
}
dispose(): void {
dispose(this._disposables);
}
get domNode(): HTMLElement {
if (!this._domNode) {
this._domNode = document.createElement('div');
const observer = new MutationObserver(_ => this._onVisibilityChanged());
observer.observe(this._domNode, { attributes: true, attributeFilter: ['monaco-visible-view-zone'] });
this._disposables.push({ dispose: () => observer.disconnect() });
}
return this._domNode;
}
private _onVisibilityChanged(): void {
if (this._domNode.hasAttribute('monaco-visible-view-zone') && !this._webview) {
this._webview = new Webview(this.domNode, document.querySelector('.monaco-editor-background'));
this._disposables.push(this._webview);
this._webview.contents = [this.htmlContent];
}
}
get afterLineNumber(): number {
return this.lineNumber;
}
get heightInLines(): number {
return 6;
}
get suppressMouseDown(): boolean {
return false;
}
}
@editorContribution
export class HtmlZoneController implements IEditorContribution {
static getInstance(editor: ICommonCodeEditor): HtmlZoneController {
return <HtmlZoneController>editor.getContribution('htmlZoneContribution');
}
private _editor: ICodeEditor;
private _zones: HtmlZone[] = [];
constructor(editor: ICodeEditor) {
this._editor = editor;
this._editor.onDidChangeModel(() => this._zones = dispose(this._zones));
}
getId(): string {
return 'htmlZoneContribution';
}
dispose(): void {
dispose(this._zones);
}
addZone(lineNumber: number, htmlContents: string): void {
const zone = new HtmlZone(lineNumber, htmlContents);
this._zones.push(zone);
this._editor.changeViewZones(accessor => {
zone.zoneId = accessor.addZone(zone);
console.log('ADDED new zone #', zone.zoneId);
});
}
}
......@@ -49,7 +49,7 @@ export default class Webview {
private _onDidClickLink = new Emitter<URI>();
private _onDidLoadContent = new Emitter<{ stats: any }>();
constructor(private _parent: HTMLElement, private _styleElement: Element) {
constructor(parent: HTMLElement, private _styleElement: Element) {
this._webview = <any>document.createElement('webview');
this._webview.style.width = '100%';
......@@ -96,7 +96,9 @@ export default class Webview {
})
];
this._parent.appendChild(this._webview);
if (parent) {
parent.appendChild(this._webview);
}
}
dispose(): void {
......@@ -109,6 +111,10 @@ export default class Webview {
}
}
get domNode(): HTMLElement {
return this._webview;
}
get onDidClickLink(): Event<URI> {
return this._onDidClickLink.event;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册