提交 1ebfb1b6 编写于 作者: A Alex Dima

Add createDiffNavigator API

上级 50e1f4f2
......@@ -53,7 +53,11 @@ declare module monaco {
declare module monaco.editor {
#includeAll(vs/editor/browser/standalone/standaloneEditor;modes.=>languages.):
#include(vs/editor/browser/standalone/standaloneCodeEditor): IEditorConstructionOptions, IDiffEditorConstructionOptions
#include(vs/editor/browser/standalone/standaloneCodeEditor): IEditorConstructionOptions, IDiffEditorConstructionOptions, IStandaloneCodeEditor, IStandaloneDiffEditor
export interface ICommandHandler {
(...args:any[]): void;
}
#include(vs/platform/keybinding/common/keybindingService): IKeybindingContextKey
#include(vs/editor/browser/standalone/standaloneServices): IEditorOverrideServices
#include(vs/platform/markers/common/markers): IMarkerData
#include(vs/editor/browser/standalone/colorizer): IColorizerOptions, IColorizerElementOptions
......
{
"name": "monaco-editor-core",
"private": true,
"version": "0.4.1",
"version": "0.4.2",
"description": "A browser based code editor",
"author": "Microsoft Corporation",
"license": "MIT",
......
......@@ -7,11 +7,9 @@
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {IContextViewService} from 'vs/platform/contextview/browser/contextView';
import {IEditorService} from 'vs/platform/editor/common/editor';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {AbstractKeybindingService} from 'vs/platform/keybinding/browser/keybindingServiceImpl';
import {ICommandHandler, IKeybindingContextKey, IKeybindingService} from 'vs/platform/keybinding/common/keybindingService';
import {IMarkerService} from 'vs/platform/markers/common/markers';
import {RemoteTelemetryServiceHelper} from 'vs/platform/telemetry/common/remoteTelemetryService';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IActionDescriptor, ICodeEditorWidgetCreationOptions, IDiffEditorOptions, IModel, IModelChangedEvent, EventType} from 'vs/editor/common/editorCommon';
......@@ -21,6 +19,7 @@ import {StandaloneKeybindingService} from 'vs/editor/browser/standalone/simpleSe
import {IEditorContextViewService, IEditorOverrideServices, ensureStaticPlatformServices, getOrCreateStaticServices} from 'vs/editor/browser/standalone/standaloneServices';
import {CodeEditorWidget} from 'vs/editor/browser/widget/codeEditorWidget';
import {DiffEditorWidget} from 'vs/editor/browser/widget/diffEditorWidget';
import {ICodeEditor, IDiffEditor} from 'vs/editor/browser/editorBrowser';
/**
* The options to create an editor.
......@@ -44,12 +43,22 @@ export interface IEditorConstructionOptions extends ICodeEditorWidgetCreationOpt
export interface IDiffEditorConstructionOptions extends IDiffEditorOptions {
}
export class StandaloneEditor extends CodeEditorWidget {
export interface IStandaloneCodeEditor extends ICodeEditor {
addCommand(keybinding:number, handler:ICommandHandler, context:string): string;
createContextKey<T>(key: string, defaultValue: T): IKeybindingContextKey<T>;
addAction(descriptor:IActionDescriptor): void;
}
export interface IStandaloneDiffEditor extends IDiffEditor {
addCommand(keybinding:number, handler:ICommandHandler, context:string): string;
createContextKey<T>(key: string, defaultValue: T): IKeybindingContextKey<T>;
addAction(descriptor:IActionDescriptor): void;
}
export class StandaloneEditor extends CodeEditorWidget implements IStandaloneCodeEditor {
private _editorService:IEditorService;
private _standaloneKeybindingService: StandaloneKeybindingService;
private _contextViewService:IEditorContextViewService;
private _markerService: IMarkerService;
private _ownsModel:boolean;
private _toDispose2: IDisposable[];
......@@ -61,9 +70,7 @@ export class StandaloneEditor extends CodeEditorWidget {
@ICodeEditorService codeEditorService: ICodeEditorService,
@IKeybindingService keybindingService: IKeybindingService,
@ITelemetryService telemetryService: ITelemetryService,
@IContextViewService contextViewService: IContextViewService,
@IEditorService editorService: IEditorService,
@IMarkerService markerService: IMarkerService
@IContextViewService contextViewService: IContextViewService
) {
if (keybindingService instanceof AbstractKeybindingService) {
(<AbstractKeybindingService><any>keybindingService).setInstantiationService(instantiationService);
......@@ -77,8 +84,6 @@ export class StandaloneEditor extends CodeEditorWidget {
}
this._contextViewService = <IEditorContextViewService>contextViewService;
this._editorService = editorService;
this._markerService = markerService;
this._toDispose2 = toDispose;
let model: IModel = null;
......@@ -110,10 +115,6 @@ export class StandaloneEditor extends CodeEditorWidget {
this.dispose();
}
public getMarkerService():IMarkerService {
return this._markerService;
}
public addCommand(keybinding:number, handler:ICommandHandler, context:string): string {
if (!this._standaloneKeybindingService) {
console.warn('Cannot add command because the editor is configured with an unrecognized KeybindingService');
......@@ -146,14 +147,6 @@ export class StandaloneEditor extends CodeEditorWidget {
}
}
public getTelemetryService():ITelemetryService {
return this._telemetryService;
}
public getEditorService():IEditorService {
return this._editorService;
}
_attachModel(model:IModel):void {
super._attachModel(model);
if (this._view) {
......@@ -170,13 +163,11 @@ export class StandaloneEditor extends CodeEditorWidget {
}
}
export class StandaloneDiffEditor extends DiffEditorWidget {
export class StandaloneDiffEditor extends DiffEditorWidget implements IStandaloneDiffEditor {
private _contextViewService:IEditorContextViewService;
private _standaloneKeybindingService: StandaloneKeybindingService;
private _toDispose2: IDisposable[];
private _markerService: IMarkerService;
private _telemetryService: ITelemetryService;
constructor(
domElement:HTMLElement,
......@@ -185,9 +176,6 @@ export class StandaloneDiffEditor extends DiffEditorWidget {
@IInstantiationService instantiationService: IInstantiationService,
@IKeybindingService keybindingService: IKeybindingService,
@IContextViewService contextViewService: IContextViewService,
@IEditorService editorService: IEditorService,
@IMarkerService markerService: IMarkerService,
@ITelemetryService telemetryService: ITelemetryService,
@IEditorWorkerService editorWorkerService: IEditorWorkerService
) {
if (keybindingService instanceof AbstractKeybindingService) {
......@@ -202,9 +190,6 @@ export class StandaloneDiffEditor extends DiffEditorWidget {
this._contextViewService = <IEditorContextViewService>contextViewService;
this._markerService = markerService;
this._telemetryService = telemetryService;
this._toDispose2 = toDispose;
this._contextViewService.setContainer(this._containerDomElement);
......@@ -219,10 +204,6 @@ export class StandaloneDiffEditor extends DiffEditorWidget {
this.dispose();
}
public getMarkerService():IMarkerService {
return this._markerService;
}
public addCommand(keybinding:number, handler:ICommandHandler, context:string): string {
if (!this._standaloneKeybindingService) {
console.warn('Cannot add command because the editor is configured with an unrecognized KeybindingService');
......@@ -254,10 +235,6 @@ export class StandaloneDiffEditor extends DiffEditorWidget {
});
}
}
public getTelemetryService():ITelemetryService {
return this._telemetryService;
}
}
export var startup = (function() {
......
......@@ -9,7 +9,7 @@ import 'vs/css!./media/standalone-tokens';
import * as editorCommon from 'vs/editor/common/editorCommon';
import {ContentWidgetPositionPreference, OverlayWidgetPositionPreference} from 'vs/editor/browser/editorBrowser';
import {ShallowCancelThenPromise} from 'vs/base/common/async';
import {StandaloneEditor, StandaloneDiffEditor, startup, IEditorConstructionOptions, IDiffEditorConstructionOptions} from 'vs/editor/browser/standalone/standaloneCodeEditor';
import {StandaloneEditor, IStandaloneCodeEditor, StandaloneDiffEditor, IStandaloneDiffEditor, startup, IEditorConstructionOptions, IDiffEditorConstructionOptions} from 'vs/editor/browser/standalone/standaloneCodeEditor';
import {ScrollbarVisibility} from 'vs/base/browser/ui/scrollbar/scrollableElementOptions';
import {IEditorOverrideServices, ensureDynamicPlatformServices, ensureStaticPlatformServices} from 'vs/editor/browser/standalone/standaloneServices';
import {IDisposable} from 'vs/base/common/lifecycle';
......@@ -20,12 +20,12 @@ import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollect
import {InstantiationService} from 'vs/platform/instantiation/common/instantiationService';
import {IModel} from 'vs/editor/common/editorCommon';
import {IModelService} from 'vs/editor/common/services/modelService';
import {ICodeEditor, IDiffEditor} from 'vs/editor/browser/editorBrowser';
import {Colorizer, IColorizerElementOptions, IColorizerOptions} from 'vs/editor/browser/standalone/colorizer';
import {SimpleEditorService} from 'vs/editor/browser/standalone/simpleServices';
import * as modes from 'vs/editor/common/modes';
import {EditorWorkerClient} from 'vs/editor/common/services/editorWorkerServiceImpl';
import {IMarkerData} from 'vs/platform/markers/common/markers';
import {DiffNavigator} from 'vs/editor/contrib/diffNavigator/common/diffNavigator';
function shallowClone<T>(obj:T): T {
let r:T = <any>{};
......@@ -51,7 +51,7 @@ export function setupServices(services: IEditorOverrideServices): IEditorOverrid
* `domElement` should be empty (not contain other dom nodes).
* The editor will read the size of `domElement`.
*/
export function create(domElement:HTMLElement, options?:IEditorConstructionOptions, services?:IEditorOverrideServices):ICodeEditor {
export function create(domElement:HTMLElement, options?:IEditorConstructionOptions, services?:IEditorOverrideServices):IStandaloneCodeEditor {
startup.initStaticServicesIfNecessary();
services = shallowClone(services);
......@@ -76,7 +76,7 @@ export function create(domElement:HTMLElement, options?:IEditorConstructionOptio
* `domElement` should be empty (not contain other dom nodes).
* The editor will read the size of `domElement`.
*/
export function createDiffEditor(domElement:HTMLElement, options?:IDiffEditorConstructionOptions, services?: IEditorOverrideServices):IDiffEditor {
export function createDiffEditor(domElement:HTMLElement, options?:IDiffEditorConstructionOptions, services?: IEditorOverrideServices):IStandaloneDiffEditor {
startup.initStaticServicesIfNecessary();
services = shallowClone(services);
......@@ -96,6 +96,23 @@ export function createDiffEditor(domElement:HTMLElement, options?:IDiffEditorCon
return result;
}
export interface IDiffNavigator {
canNavigate():boolean;
next():void;
previous():void;
dispose():void;
}
export interface IDiffNavigatorOptions {
followsCaret?:boolean;
ignoreCharChanges?:boolean;
alwaysRevealFirst?:boolean;
}
export function createDiffNavigator(diffEditor:IStandaloneDiffEditor, opts?:IDiffNavigatorOptions): IDiffNavigator {
return new DiffNavigator(diffEditor, opts);
}
function prepareServices(domElement: HTMLElement, services: IEditorOverrideServices): { ctx: IEditorOverrideServices; toDispose: IDisposable[]; } {
services = ensureStaticPlatformServices(services);
var toDispose = ensureDynamicPlatformServices(domElement, services);
......@@ -371,6 +388,7 @@ export function createMonacoEditorAPI(): typeof monaco.editor {
// methods
create: create,
createDiffEditor: createDiffEditor,
createDiffNavigator: createDiffNavigator,
createModel: createModel,
setModelLanguage: setModelLanguage,
......
......@@ -752,14 +752,29 @@ declare module monaco.editor {
* `domElement` should be empty (not contain other dom nodes).
* The editor will read the size of `domElement`.
*/
export function create(domElement: HTMLElement, options?: IEditorConstructionOptions, services?: IEditorOverrideServices): ICodeEditor;
export function create(domElement: HTMLElement, options?: IEditorConstructionOptions, services?: IEditorOverrideServices): IStandaloneCodeEditor;
/**
* Create a new diff editor under `domElement`.
* `domElement` should be empty (not contain other dom nodes).
* The editor will read the size of `domElement`.
*/
export function createDiffEditor(domElement: HTMLElement, options?: IDiffEditorConstructionOptions, services?: IEditorOverrideServices): IDiffEditor;
export function createDiffEditor(domElement: HTMLElement, options?: IDiffEditorConstructionOptions, services?: IEditorOverrideServices): IStandaloneDiffEditor;
export interface IDiffNavigator {
canNavigate(): boolean;
next(): void;
previous(): void;
dispose(): void;
}
export interface IDiffNavigatorOptions {
followsCaret?: boolean;
ignoreCharChanges?: boolean;
alwaysRevealFirst?: boolean;
}
export function createDiffNavigator(diffEditor: IStandaloneDiffEditor, opts?: IDiffNavigatorOptions): IDiffNavigator;
/**
* Create a new editor model.
......@@ -879,6 +894,26 @@ declare module monaco.editor {
export interface IDiffEditorConstructionOptions extends IDiffEditorOptions {
}
export interface IStandaloneCodeEditor extends ICodeEditor {
addCommand(keybinding: number, handler: ICommandHandler, context: string): string;
createContextKey<T>(key: string, defaultValue: T): IKeybindingContextKey<T>;
addAction(descriptor: IActionDescriptor): void;
}
export interface IStandaloneDiffEditor extends IDiffEditor {
addCommand(keybinding: number, handler: ICommandHandler, context: string): string;
createContextKey<T>(key: string, defaultValue: T): IKeybindingContextKey<T>;
addAction(descriptor: IActionDescriptor): void;
}
export interface ICommandHandler {
(...args: any[]): void;
}
export interface IKeybindingContextKey<T> {
set(value: T): void;
reset(): void;
}
export interface IEditorOverrideServices {
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册