Add befor/after decorations

This commit is contained in:
Martin Aeschlimann
2016-06-03 08:48:28 +02:00
parent afbe654bdd
commit c989011128
12 changed files with 567 additions and 92 deletions

View File

@@ -13,7 +13,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {Remotable, IThreadService} from 'vs/platform/thread/common/thread';
import {ExtHostModelService, ExtHostDocumentData} from 'vs/workbench/api/node/extHostDocuments';
import {Selection, Range, Position, EditorOptions, EndOfLine} from './extHostTypes';
import {ISingleEditOperation, ISelection, IRange, IEditor, EditorType, ICommonCodeEditor, ICommonDiffEditor, IDecorationRenderOptions, IRangeWithMessage} from 'vs/editor/common/editorCommon';
import {ISingleEditOperation, ISelection, IRange, IEditor, EditorType, ICommonCodeEditor, ICommonDiffEditor, IDecorationRenderOptions, IDecorationOptions} from 'vs/editor/common/editorCommon';
import {ICodeEditorService} from 'vs/editor/common/services/codeEditorService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {Position as EditorPosition} from 'vs/platform/editor/common/editor';
@@ -689,7 +689,7 @@ export class MainThreadEditors {
return TPromise.as(null);
}
_trySetDecorations(id: string, key: string, ranges: IRangeWithMessage[]): TPromise<any> {
_trySetDecorations(id: string, key: string, ranges: IDecorationOptions[]): TPromise<any> {
if (!this._textEditorsMap[id]) {
return TPromise.wrapError('TextEditor disposed');
}

View File

@@ -11,7 +11,7 @@ import {IDisposable} from 'vs/base/common/lifecycle';
import * as modes from 'vs/editor/common/modes';
import * as types from './extHostTypes';
import {Position as EditorPosition} from 'vs/platform/editor/common/editor';
import {IPosition, ISelection, IRange, IRangeWithMessage, ISingleEditOperation} from 'vs/editor/common/editorCommon';
import {IPosition, ISelection, IRange, IDecorationOptions, ISingleEditOperation} from 'vs/editor/common/editorCommon';
import {IHTMLContentElement} from 'vs/base/common/htmlContent';
import {ITypeBearing} from 'vs/workbench/parts/search/common/search';
import * as vscode from 'vscode';
@@ -155,27 +155,28 @@ function fromMarkedStringOrMarkedStringArr(something: vscode.MarkedString | vsco
}
}
function isRangeWithMessage(something: any): something is vscode.DecorationOptions {
return (typeof something.range !== 'undefined');
function isDecorationOptions(something: any): something is vscode.DecorationOptions {
return (typeof something.range !== 'undefined') || (typeof something.after !== 'undefined') || (typeof something.before !== 'undefined');
}
function isRangeWithMessageArr(something: vscode.Range[]|vscode.DecorationOptions[]): something is vscode.DecorationOptions[] {
function isDecorationOptionsArr(something: vscode.Range[]|vscode.DecorationOptions[]): something is vscode.DecorationOptions[] {
if (something.length === 0) {
return true;
}
return isRangeWithMessage(something[0]) ? true : false;
return isDecorationOptions(something[0]) ? true : false;
}
export function fromRangeOrRangeWithMessage(ranges:vscode.Range[]|vscode.DecorationOptions[]): IRangeWithMessage[] {
if (isRangeWithMessageArr(ranges)) {
return ranges.map((r): IRangeWithMessage => {
export function fromRangeOrRangeWithMessage(ranges:vscode.Range[]|vscode.DecorationOptions[]): IDecorationOptions[] {
if (isDecorationOptionsArr(ranges)) {
return ranges.map((r): IDecorationOptions => {
return {
range: fromRange(r.range),
hoverMessage: fromMarkedStringOrMarkedStringArr(r.hoverMessage)
hoverMessage: fromMarkedStringOrMarkedStringArr(r.hoverMessage),
renderOptions: r.renderOptions
};
});
} else {
return ranges.map((r): IRangeWithMessage => {
return ranges.map((r): IDecorationOptions => {
return {
range: fromRange(r)
};

View File

@@ -241,7 +241,7 @@ export class MainThreadTextEditor {
}
}
public setDecorations(key: string, ranges:EditorCommon.IRangeWithMessage[]): void {
public setDecorations(key: string, ranges:EditorCommon.IDecorationOptions[]): void {
if (!this._codeEditor) {
console.warn('setDecorations on invisible editor');
return;